Jump to content

String Management not working


Recommended Posts

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 =)

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...