E1M1 Posted August 25, 2009 Posted August 25, 2009 how tosplit string after every x characters? I wanna split long 1 line sring into multiline strings, I wanna add @crlf after every 70 characters. edited
E1M1 Posted August 25, 2009 Author Posted August 25, 2009 (edited) I tried this, but it's bugsesgy, can anyone help me fix it? Following script loses some characters from original string. edit I tried to set$i start value to 0, It seems like I have now full string, but I also have some extra line ends. edit2:How to define long multiline variable? I remember It was like $var = "fffffffffff" &_ _& "ffffff" but I cant remember exactly how. ClipPut("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") $string = ClipGet() $other = "" dim $new[1] ReDim $new[Int(StringLen($string)/70) + 1] For $i = 1 to Int(StringLen($string)/70) $new[$i] = StringLeft(StringTrimLeft($string,($i*70)+$i),70) & @CRLF $other = $other & $new[$i] Next ClipPut($other) Edited August 25, 2009 by E1M1 edited
Moderators Melba23 Posted August 25, 2009 Moderators Posted August 25, 2009 E1M1, Both answers in one: $sString = "XXXXXXXYYYYYYYZZZZZZZ" & _ "XXXXXXXYYYYYYYZZZZZZZ" & _ "XXXXXXXYYYYYYYZZZZZZZ" & _ "XXXXXXXYYYYYYYZZZZZZZ" $sNewString = "" For $i = 1 To StringLen($sString) Step 7 $sNewString &= StringMid($sString, $i, 7) & @CRLF Next ConsoleWrite($sNewString & @CRLF) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
martin Posted August 25, 2009 Posted August 25, 2009 (edited) I tried this, but it's bugsesgy, can anyone help me fix it? Following script loses some characters from original string. edit I tried to set$i start value to 0, It seems like I have now full string, but I also have some extra line ends. edit2:How to define long multiline variable? I remember It was like $var = "fffffffffff" &_ _& "ffffff" but I cant remember exactly how. ClipPut("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff") $string = ClipGet() $other = "" dim $new[1] ReDim $new[Int(StringLen($string)/70) + 1] For $i = 1 to Int(StringLen($string)/70) $new[$i] = StringLeft(StringTrimLeft($string,($i*70)+$i),70) & @CRLF $other = $other & $new[$i] Next ClipPut($other) Melba23 has shown a better and simpler way to do what you want, but in case it helps here is your way corrected. $string = "fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" $other = "" dim $new[Int(StringLen($string)/70) + 1] For $i = 0 to Int(StringLen($string)/70);<---------start from 0 not 1 $new[$i] = StringLeft(StringTrimLeft($string,($i*70)),70) & @CRLF;<--------removed the +$i $other = $other & $new[$i] Next ConsoleWrite($other & @CRLF) Edited August 25, 2009 by martin Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
trancexx Posted August 25, 2009 Posted August 25, 2009 Or like this maybe: $sNewString = StringRegExpReplace($sString, "(?s)(.{70})", "$1" & @CRLF) ♡♡♡ . eMyvnE
Moderators Melba23 Posted August 25, 2009 Moderators Posted August 25, 2009 I just knew an SRE guru would turn up sooner or later.... >_< M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
E1M1 Posted August 25, 2009 Author Posted August 25, 2009 what his part does?It's too hard for me to understand it. "(?s)(.{70})", "$1" edited
PsaltyDS Posted August 25, 2009 Posted August 25, 2009 what his part does?It's too hard for me to understand it."(?s)(.{70})", "$1"Look in your help file at StringRegExp() for a basic description of regular expressions. That one used in StringRegExpReplace() sez:"(?s)" = "While matching any character including whitespaces...""(.{70})" = "Match every group of 70 characters...""$1" & @CRLF = "Replace each matched group with the same 70 characters plus @CRLF." >_< Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
trancexx Posted August 25, 2009 Posted August 25, 2009 Look in your help file at StringRegExp() for a basic description of regular expressions. That one used in StringRegExpReplace() sez:"(?s)" = "While matching any character including whitespaces...""(.{70})" = "Match every group of 70 characters...""$1" & @CRLF = "Replace each matched group with the same 70 characters plus @CRLF." >_<"(?s)" means for dot "." that follows to match anything including newline.@Melba23, guru my ... (use your imagination ) ♡♡♡ . eMyvnE
PsaltyDS Posted August 25, 2009 Posted August 25, 2009 @Melba23, guru my ... (use your imagination )...shiny buttons? >_< Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
trancexx Posted August 26, 2009 Posted August 26, 2009 ...shiny buttons? >_<Assented....you dirty talker. ♡♡♡ . eMyvnE
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