am632 Posted April 17, 2016 Share Posted April 17, 2016 Hi, I have a text file containing numbers but I to seperate them in pairs, for example my text file looks like this... 1234567890 1234567890 1234567890 but I want it to look like this 12 34 56 78 90 12 34 56 78 90 12 34 56 78 90 How would I do this please? I have looked in the help file at various 'string' functions but I cant find how to do what I want. Thanks Link to comment Share on other sites More sharing options...
JohnOne Posted April 17, 2016 Share Posted April 17, 2016 did you try StringFormat() AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
am632 Posted April 17, 2016 Author Share Posted April 17, 2016 Hi, I saw that in the help file but I dont understand what it means, so I'm not able to apply the example to what i'm wanting to do. Is this what I need to use to edit the string of my text file? If so could you give me an example please? Thanks Link to comment Share on other sites More sharing options...
InunoTaishou Posted April 17, 2016 Share Posted April 17, 2016 (edited) If each line is exactly 10 characters long, like in the example, you could do this Global $sString = "1234567890" & @CRLF & "2345678901" & @CRLF & "3456789012" & @CRLF & "4567890123" & @CRLF & "5678901234" & @CRLF & "6789012345" & @CRLF & "7890123456" & @CRLF & "8901234567" & @CRLF & "9012345678" & @CRLF & "0123456789" ConsoleWrite(StringRegExpReplace($sString, "(\d{2})", "$1$2$3$4 ") & @CRLF) *To clarify* If one line is more than or less than 10 characters it will still work, but that line will not have 5 columns of 2 pairs. Edited April 17, 2016 by InunoTaishou Link to comment Share on other sites More sharing options...
markyrocks Posted April 18, 2016 Share Posted April 18, 2016 (edited) $file="numbers.txt" $array=FileReadToArray($file) For $x=0 to ubound($array)-1 $newstring="" For $y=0 to ceiling(stringlen($array[$x])/2) $newstring&=stringleft($array[$x],2) & " " $array[$x]=stringtrimleft($array[$x],2) next $array[$x]=$newstring Next Fileclose($file) $file=fileopen("numbers.txt",2) For $z=0 to ubound($array)-1 Filewriteline($file, $array[$z]) Next Fileclose($file) ;...nm this quoted partcan't Idk this was for fun untested so it probably won't work right tired. .... damn phone doesnt work right all the time on this site so it likes to add and change stuff randomly. Fights me the whole time. Edited April 18, 2016 by markyrocks Spoiler "I Believe array math to be potentially fatal, I may be dying from array math poisoning" Link to comment Share on other sites More sharing options...
mikell Posted April 18, 2016 Share Posted April 18, 2016 A little more versatile $sString = "12345678901" & @CRLF & "2345678901" & @CRLF & "3456789012" & @CRLF & "4567890123" & @CRLF & "5678901234" & @CRLF & "6789012345" & @CRLF & "7890123456" & @CRLF & "8901234567" & @CRLF & "9012345678" & @CRLF & "0123456789" ; $sString = FileRead("numbers.txt") Msgbox(0,"", StringRegExpReplace($sString, "\d{2}\K", " ")) 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