Sign in to follow this  
Followers 0
Pietro42

String Management not working

4 posts in this topic

Hi everyone, I just signed in in this great community, and I already need help ;)

I have this huge list of pi digits in this pattern xxxxxxxxxx xxxxxxxxxx xxxxxxxxxx and I need it like x, x, x, x.

I wrote this code that should separate it in an array, 10 digits per element, then combine it in a huge continuos array, then separate it in an array one digit per element, and finally combine them in the right pattern.

#include <file.au3>
$nomefile1 = "Pi 100000 digits"
$nomefile2 = "PiELA"
$posizione1 = @DesktopDir & "\" & $nomefile1 & ".txt"
$posizione2 = @DesktopDir & "\" & $nomefile2 & ".txt"

$fileRAW = FileOpen($posizione1, 9)
$fileELA = FileOpen($posizione2, 9) ; which is similar to 1 + 8 (append to endoffile + create dir)
If $fileRAW = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
Else
Global $pi = FileRead($fileRAW)
FileWriteLine($fileELA, $pi)

Global $piseparato = StringSplit($pi, " ") ;separating 10 digits per element

Global $piunito
Global $pifinale

For $x = 1 To $piseparato[0]
$piunito = $piunito & $piseparato[$x] ;combining in a huge array
Next

FileWriteLine($fileELA, $piunito)

$piseparato = StringSplit($piunito, "") ;splitting 1 digit per element

For $x = 1 To $piseparato[0]
$pifinale = $pifinale & ", " & $piseparato[$x] ;combining in the right pattern
Next
FileWriteLine($fileELA, $pifinale)

EndIf
FileClose($fileRAW)
FileClose($fileELA)

But it doesn't work... wrong sintax or wrong logic?

Thank you in advance and sorry for the English =)

Share this post


Link to post
Share on other sites



So are you saying if you start with 1234567891 2345678912 3456789123 5678987654

you want it to look like this: 1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,4,5,6,7,8,9,1,2,3,5,6,7,8,9,8,7,6,5,4?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

What happens when you run the code you have? Errors or anything? what does to write?

Trying to help, not sure if it would work. Try it though! :bye:

_FileReadToArray($filePath, $nameOfArrayToSaveAs)
$VarForFileWrite = ""
For $Line = 1 To $nameOfArrayToSaveAs[0] ;for every line in file
$charSplit = StringSplit($nameOfArrayToSaveAs, "") ; splits the line into an array 1 element for each char.
For $char To $charSplit[0] ;for every char on line
$VarForFileWrite = $VarForFileWrite &","
Next
Next
FileWriteLine($NewFilePath,$VarForFileWrite)
Edited by Attckdog

A true renaissance man

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

My go:

$string = "1234567891 2345678912 3456789123 5678987654"
$result = ""
$aDigits = StringRegExp($string, 'd', 3)
For $each In $aDigits
$result &= $each & ','
Next
$result = StringTrimRight($result, 1)
MsgBox(0, "", $result)

Edit: Added autoit code tags

Edited by MrMitchell

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