fxg4758 Posted October 9, 2014 Share Posted October 9, 2014 (edited) Hi all. I need to split a text in 900 characters to send a message in small pieces. But i have problem in split without break phrases that finhished with (.) I´m try this function from Siao. Regards. #include <Array.au3> $Fox = _StringChop("abcdsd",4) _ArrayDisplay($Fox) Func _StringChop($string, $size) $count = Ceiling(StringLen($string)/$size) Dim $array[$count+1], $start = 1 For $i = 1 To $count $array[$i] = StringMid($string, $start, $size) $start += $size Next $array[0] = UBound($array) - 1 Return $array EndFunc Edited October 9, 2014 by fxg4758 Link to comment Share on other sites More sharing options...
guinness Posted October 10, 2014 Share Posted October 10, 2014 #include <Array.au3> Local $sString = '' For $i = 0 To 999 $sString &= Chr(Random(97, 122, 1)) Next Local $aSplit = StringRegExp($sString, '[A-Za-z]{1,900}', $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aSplit) I also searched and found so many posts, this one stood out... though is slightly different than mine as you didn't provide an example. It's up to you to change to suit your needs. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
fxg4758 Posted October 10, 2014 Author Share Posted October 10, 2014 #include <Array.au3> Local $sString = '' For $i = 0 To 999 $sString &= Chr(Random(97, 122, 1)) Next Local $aSplit = StringRegExp($sString, '[A-Za-z]{1,900}', $STR_REGEXPARRAYGLOBALMATCH) _ArrayDisplay($aSplit) I also searched and found so many posts, this one stood out... though is slightly different than mine as you didn't provide an example. It's up to you to change to suit your needs. Hi guinness! Thanks a lot for your post! Link to comment Share on other sites More sharing options...
guinness Posted October 10, 2014 Share Posted October 10, 2014 You're welcome. Please mark as solved if it solved your problem. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted October 10, 2014 Share Posted October 10, 2014 (edited) fxg4758, This will split a string into lines on word boundries. You define how long the line will be... #include <array.au3> local $str, $ilength = 50 $str &= 'Bacon ipsum dolor sit amet chicken shank swine brisket ball tip, pancetta andouille pig capicola frankfurter bresaola corned beef biltong ribeye.' & @CRLF $str &= "Ham beef shankle meatball pork loin hamburger. Testing can't" & @CRLF $str &= 'Pig beef ribs brisket shankle turkey ribeye frankfurter prosciutto. Landjaeger pork chop andouille jerky, prosciutto spare ribs turducken ham' & @CRLF $str &= 'hock tail sausage pork belly rump tri-tip strip steak tongue. Doner hamburger ribeye meatball turducken andouille ' & @CRLF $str &= 'shankle ham t-bone pork. Brisket chicken andouille kevin rump, pork loin frankfurter. Beef pastrami beef ribs shank pork belly corned beef' & @CRLF $str &= 'drumstick tri-tip venison ham hock ball tip.' & @CRLF local $aRET = stringregexp(stringregexpreplace($str,'\R',' '),'.{1,' & $ilength & '} ',3) ConsoleWrite(@error ? '@error = ' & @error : _ArrayToString($aRET,@crlf) & @CRLF) kylomas edit: corrected code Edited October 11, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
mikell Posted October 11, 2014 Share Posted October 11, 2014 Local $sString = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse lectus tortor dignissim sit amet, adipiscing nec ultricies sed dolor. Cras elementum ultrices diam. Maecenas ligula massa varius a semper congue euismod non mi. Proin porttitor orci nec nonummy molestie enim est eleifend mi, non fermentum diam nisl sit amet erat. Duis semper. Duis arcu massa scelerisque vitae consequat in pretium a enim. Pellentesque congue. Ut in risus volutpat libero pharetra tempor. Cras vestibulum bibendum augue. Praesent egestas leo in pede. Praesent blandit odio eu enim. Pellentesque sed dui ut augue blandit sodales.' $n = 40 $res = StringRegExpReplace($sString, '[^.,]{1,' & $n-1 & '}((?:,|\.)?\h|\.?$)\K', @CRLF) Msgbox(0,"", $res) Link to comment Share on other sites More sharing options...
fxg4758 Posted October 14, 2014 Author Share Posted October 14, 2014 Hi. Thanks to all that helped me! I manage to adapt your code to my needs. Link to comment Share on other sites More sharing options...
fxg4758 Posted October 16, 2014 Author Share Posted October 16, 2014 Hi. I´m trying to adapt the code, but i have a problem. Everythings works until i got the last text. The loop writes only the title and don´t exit the function. Thanks for any help. expandcollapse popup$position = 1 $title = "example title" $ilength = 1200 - StringLen($title) $text = "Xxxx. Xxxedfsdfsd, sdfdsf, sdaasd: ddsdfsdf." $width = "1024" $height = "768" $oIE = _IECreateEmbedded() (...) while 2 $aRET = stringregexp(stringregexpreplace($text,'\R',' '),'.{1,' & $ilength & '} ',3,$position) If IsArray($aRET) Then Local $array = StringSplit($aRET[0], '.', 1) $element = LastElement($array) $newlength = StringLen($aRET[0]) - StringLen($element) $position = $position + $newlength $Fox = StringMid($aRET[0], 1, $newlength) ConsoleWrite($title & @CRLF & StringStripWS($Fox,1) & @CRLF) Else ExitLoop EndIf WEnd Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Link to comment Share on other sites More sharing options...
kylomas Posted October 16, 2014 Share Posted October 16, 2014 (edited) Use mikell's SRE as it accounts for punctuation, like this... $sRET = StringRegExpReplace($text, '[^.,]{1,' & $ilength-1 & '}((?:,|\.)?\h|\.?$)\K', @CRLF) kylomas edit: As far as exiting the loop, stringregexp will always return an array (assuming the syntax is valid) therefore you have no way to exit with your current logic. Edited October 16, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
fxg4758 Posted October 17, 2014 Author Share Posted October 17, 2014 Use mikell's SRE as it accounts for punctuation, like this... $sRET = StringRegExpReplace($text, '[^.,]{1,' & $ilength-1 & '}((?:,|\.)?\h|\.?$)\K', @CRLF) kylomas edit: As far as exiting the loop, stringregexp will always return an array (assuming the syntax is valid) therefore you have no way to exit with your current logic. Hi kylomas, If i use this mikell´s SRE with stringregexp, i cannot get any text. Regards. Link to comment Share on other sites More sharing options...
kylomas Posted October 17, 2014 Share Posted October 17, 2014 (edited) Is this what you are looking for...? expandcollapse popup#include <ie.au3> $position = 1 $title = "example title" $ilength = 1200 - StringLen($title) $text = "Xxxx. Xxxedfsdfsd, sdfdsf, sdaasd: ddsdfsdf." $width = "1024" $height = "768" $oIE = _IECreateEmbedded() ;(...) while 2 $aRET = stringregexp(stringregexpreplace($text,'\R',' '),'.{1,' & $ilength & '} ',3, $position) If IsArray($aRET) Then Local $array = StringSplit($aRET[0], '.', 1) $element = LastElement($array) $newlength = StringLen($aRET[0]) - StringLen($element) $position = $position + $newlength $Fox = StringMid($aRET[0], 1, $newlength) ConsoleWrite($title & @CRLF & StringStripWS($Fox,1) & @CRLF) exitloop ; get out of loop Else ExitLoop EndIf WEnd Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Either your requirements are changing or I am NOT following you... kylomas edit: Can you explain what you want the while...wend loop to do??? And a REAL life example would help... Edited October 17, 2014 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
fxg4758 Posted October 17, 2014 Author Share Posted October 17, 2014 Is this what you are looking for...? expandcollapse popup#include <ie.au3> $position = 1 $title = "example title" $ilength = 1200 - StringLen($title) $text = "Xxxx. Xxxedfsdfsd, sdfdsf, sdaasd: ddsdfsdf." $width = "1024" $height = "768" $oIE = _IECreateEmbedded() ;(...) while 2 $aRET = stringregexp(stringregexpreplace($text,'\R',' '),'.{1,' & $ilength & '} ',3, $position) If IsArray($aRET) Then Local $array = StringSplit($aRET[0], '.', 1) $element = LastElement($array) $newlength = StringLen($aRET[0]) - StringLen($element) $position = $position + $newlength $Fox = StringMid($aRET[0], 1, $newlength) ConsoleWrite($title & @CRLF & StringStripWS($Fox,1) & @CRLF) exitloop ; get out of loop Else ExitLoop EndIf WEnd Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Either your requirements are changing or I am NOT following you... kylomas Hi kylomas. I need to replace the function initial because i have to use a outside site to put the text. It´s a thing that change from a day to another. Regards. Link to comment Share on other sites More sharing options...
kylomas Posted October 17, 2014 Share Posted October 17, 2014 fxg4758, See my last post. Edit added.. Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
kylomas Posted October 17, 2014 Share Posted October 17, 2014 Run your script like this. I don't think you are returning what you expect from the SRE... expandcollapse popup#include <ie.au3> #include <array.au3> $position = 1 $title = "example title" $ilength = 1200 - StringLen($title) $text = "Xxxx. Xxxedfsdfsd, sdfdsf, sdaasd: ddsdfsdf." $width = "1024" $height = "768" $oIE = _IECreateEmbedded() ;(...) while 2 $aRET = stringregexp(stringregexpreplace($text,'\R',' '),'.{1,' & $ilength & '} ',3, $position) _arraydisplay($aRET) If IsArray($aRET) Then Local $array = StringSplit($aRET[0], '.', 1) $element = LastElement($array) $newlength = StringLen($aRET[0]) - StringLen($element) ; this = 0 $position = $position + $newlength $Fox = StringMid($aRET[0], 1, $newlength) ConsoleWrite($title & @CRLF & StringStripWS($Fox,1) & @CRLF) Else ExitLoop EndIf WEnd Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
fxg4758 Posted October 17, 2014 Author Share Posted October 17, 2014 Is this what you are looking for...? expandcollapse popup#include <ie.au3> $position = 1 $title = "example title" $ilength = 1200 - StringLen($title) $text = "Xxxx. Xxxedfsdfsd, sdfdsf, sdaasd: ddsdfsdf." $width = "1024" $height = "768" $oIE = _IECreateEmbedded() ;(...) while 2 $aRET = stringregexp(stringregexpreplace($text,'\R',' '),'.{1,' & $ilength & '} ',3, $position) If IsArray($aRET) Then Local $array = StringSplit($aRET[0], '.', 1) $element = LastElement($array) $newlength = StringLen($aRET[0]) - StringLen($element) $position = $position + $newlength $Fox = StringMid($aRET[0], 1, $newlength) ConsoleWrite($title & @CRLF & StringStripWS($Fox,1) & @CRLF) exitloop ; get out of loop Else ExitLoop EndIf WEnd Func LastElement(ByRef Const $array) Return $Array[UBound($array)-1] EndFunc ;==>$lastElement Either your requirements are changing or I am NOT following you... kylomas edit: Can you explain what you want the while...wend loop to do??? And a REAL life example would help... Hi kylomas. I have a program that create a internet explorer window that enter in a site. The while.... wend is to insert text in that site and then close the window and return to the master program. I try to do a Next... For... but it cames stuck when the window is created. Regards. Link to comment Share on other sites More sharing options...
kylomas Posted October 17, 2014 Share Posted October 17, 2014 Post an example / reproducer of a failure or we are just guessing... Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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