Sign in to follow this  
Followers 0
E1M1

simple string split question

12 posts in this topic

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (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 by E1M1

edited

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (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 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.

Share this post


Link to post
Share on other sites

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._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

what his part does?It's too hard for me to understand it.

"(?s)(.{70})", "$1"


edited

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

thanks


edited

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
Share on other sites

...shiny buttons?

>_<

Assented.

...you dirty talker.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0