andrew2 Posted December 8, 2008 Share Posted December 8, 2008 i am looking for a way to cuut a long sentence afer X chars i tried to count the stringlenght with StringLen search for a whitespace and cut the string there with StringSplit but it wouldnt hel at all does anybody has a tip for me Link to comment Share on other sites More sharing options...
Valuater Posted December 8, 2008 Share Posted December 8, 2008 Maybe,,, $string = "123456789 abcdefghi" $split = StringSplit($string, " ") MsgBox(0x0, "", $split[1]) 8) Link to comment Share on other sites More sharing options...
Rental Posted December 8, 2008 Share Posted December 8, 2008 StringLeft ( "string", count ) cuts the end off the string after X chars Link to comment Share on other sites More sharing options...
andrew2 Posted December 8, 2008 Author Share Posted December 8, 2008 i know all both functions but i need to cut the sentence after x chars and make a twoline text out of it. short explain of my problem would be nice hehe i got a textbox in a gui the textbox is used to retrieve messages from a webpage mostly just text. the textbox has a char limit of 65 what it can display but if i got a text which is 100 chars or more i got displaying problems and would need a scrollbar and i dont want scrollbars so cut the sentence each 65 char and put it to the next line. Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 8, 2008 Share Posted December 8, 2008 Use StringLeft and then StringMid... $sString = "Some long Data..." $s65Chars = StringLeft($sString, 65) $sAfter65Chars = StringMid($sString, 66) Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
andrew2 Posted December 8, 2008 Author Share Posted December 8, 2008 ok is there a way to repeat this until the end of the sentence is reached Link to comment Share on other sites More sharing options...
KaFu Posted December 8, 2008 Share Posted December 8, 2008 (edited) Have such a function in my script SMF... expandcollapse popup#include<GUIConstantsEx.au3> #include<array.au3> Local $msg GUICreate("My GUI",250,150) ; will create a dialog box that when displayed is centered $c_label = GUICtrlCreateLabel("",20,20,200,200) GUICtrlSetFont(-1, 8, 400, 0, 'Lucida Console') GUICtrlSetData(-1,_String_Wrap( "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi" _ & "jklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqr" _ & "stuvwxyzabcdefghijklmnopqrstuvwxyz", 30)) GUISetState(@SW_SHOW) ; will display an empty dialog box ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop WEnd GUIDelete() Func _String_Wrap($sString_Wrap_StringToSplit = "", $iString_Wrap_NoCharacters = 20) Local $aString_Wrap_StringToSplit, $aString_Wrap_StringToSplit_Save If StringLen($sString_Wrap_StringToSplit) > $iString_Wrap_NoCharacters Then StringReplace($sString_Wrap_StringToSplit, @CRLF, @LF) $aString_Wrap_StringToSplit = StringSplit($sString_Wrap_StringToSplit, @LF) For $i = 1 To UBound($aString_Wrap_StringToSplit) - 1 $aString_Wrap_StringToSplit_Save = "" While StringLen($aString_Wrap_StringToSplit[$i]) > $iString_Wrap_NoCharacters $aString_Wrap_StringToSplit_Save &= StringLeft($aString_Wrap_StringToSplit[$i], $iString_Wrap_NoCharacters) & @LF $aString_Wrap_StringToSplit[$i] = StringRight($aString_Wrap_StringToSplit[$i], StringLen($aString_Wrap_StringToSplit[$i]) - $iString_Wrap_NoCharacters) WEnd $aString_Wrap_StringToSplit[$i] = $aString_Wrap_StringToSplit_Save & $aString_Wrap_StringToSplit[$i] Next Return _ArrayToString($aString_Wrap_StringToSplit, "", 1) Else Return $sString_Wrap_StringToSplit EndIf EndFunc ;==>_String_Wrap If you use it on a label combined with the monospace font GUICtrlSetFont($c_label, 8, 400, 0, 'Lucida Console') the relative max-size always stays the same... Edited December 8, 2008 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
andrew2 Posted December 8, 2008 Author Share Posted December 8, 2008 (edited) i wrote my own little function but somehow my script stops after the first value Func _SplitStringAfterXChars ( $i_UserText, $i_StringToSplit = "<BR>", $i_StringDelimiterForce = 1) $i_Splitted = StringSplit($i_UserText,$i_StringToSplit,$i_StringDelimiterForce) $i_SplitNum = 1 While $i_SplitNum <= $i_Splitted[0] return $i_Splitted[$i_SplitNum] $i_SplitNum = $i_SplitNum + 1 WEnd EndFunc my srting delimiter is a htmlcode for nextline <BR> because my script retrieves html code my problem know if my sentence would be Hello my<BR>World my function only return Hello my and the world is complete missing i appretiate your help kafu your function is working but if i want to learn i need to know what is wrong in my function so i can to it better next time Edited December 8, 2008 by andrew2 Link to comment Share on other sites More sharing options...
KaFu Posted December 8, 2008 Share Posted December 8, 2008 Help-File Use the Return keyword to exit the function. Return should be below the wend. Create a string in the wend like $string &= @crlf & $i_Splitted[$i_SplitNum] OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
andrew2 Posted December 8, 2008 Author Share Posted December 8, 2008 (edited) Help-File Use the Return keyword to exit the function. Return should be below the wend. Create a string in the wend like $string &= @crlf & $i_Splitted[$i_SplitNum] id did now it looks like this Func _SplitStringAfterXChars ( $i_UserText, $i_StringToSplit = " ", $i_StringDelimiterForce = 1) $i_Splitted = StringSplit($i_UserText,$i_StringToSplit,$i_StringDelimiterForce) $i_SplitNum = 1 While $i_SplitNum <= $i_Splitted[0] $string &= @crlf & $i_Splitted[$i_SplitNum] $i_SplitNum = $i_SplitNum + 1 WEnd Return $string EndFunc i got the following error WARNING: $string possibly not declared/created yet EDIT : Ok fixed i just declared $string = "" on the beginning and its working now thx kafu Edited December 8, 2008 by andrew2 Link to comment Share on other sites More sharing options...
KaFu Posted December 8, 2008 Share Posted December 8, 2008 MsgBox(0, "", _SplitStringAfterXChars("Hello my<BR>World", "<BR>")) Func _SplitStringAfterXChars($i_UserText, $i_StringToSplit = " ", $i_StringDelimiterForce = 1) local $string $i_Splitted = StringSplit($i_UserText, $i_StringToSplit, $i_StringDelimiterForce) $i_SplitNum = 1 While $i_SplitNum <= $i_Splitted[0] $string &= @CRLF & $i_Splitted[$i_SplitNum] $i_SplitNum = $i_SplitNum + 1 WEnd Return $string EndFunc ;==>_SplitStringAfterXChars OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
MrCreatoR Posted December 8, 2008 Share Posted December 8, 2008 ok is there a way to repeat this until the end of the sentence is reachedYou can use StringRegExp to get an array: #include <Array.au3> #include <String.au3> $sString = _StringRepeat("Some long Data..." & @CRLF, 100) $a65Strings = StringRegExp($sString, "(?s).{0,64}[^\s]", 3) If IsArray($a65Strings) Then ConsoleWrite("[0] Lenght = " & StringLen($a65Strings[0]) & @CRLF) ConsoleWrite("[29] Lenght = " & StringLen($a65Strings[29]) & @CRLF) _ArrayDisplay($a65Strings) EndIf Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now