Jump to content
Sign in to follow this  
am632

seperate string with spaces every 2 places help

Recommended Posts

am632

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

Share this post


Link to post
Share on other sites
am632

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

Share this post


Link to post
Share on other sites
InunoTaishou

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 by InunoTaishou

Share this post


Link to post
Share on other sites
markyrocks
$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 by markyrocks

Share this post


Link to post
Share on other sites
mikell

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", " "))

 

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.