diikee Posted July 28, 2008 Share Posted July 28, 2008 #include <file.au3> $file = FileOpen("c:\misc\e.csv", 0) $sFile = @ScriptDir & "\Test1.txt" If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf Dim $aRecords If Not _FileReadToArray("c:\misc\e.csv",$aRecords) Then MsgBox(4096,"Error", " Error reading error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] $rec = StringSplit($aRecords, ",") _FileWriteFromArray($sFile, $rec, 1) Next FileClose($file) I am reading a CSV file to an array but I want to split the entries in the file and print them one at a time. instead of me,you,them,ours... i want me, you, them, ours, Link to comment Share on other sites More sharing options...
Paulie Posted July 28, 2008 Share Posted July 28, 2008 Stringsplit() I don't understand your question? If you have a comma delimiter string and want to seperate it by the commas, the Stringsplit is the function for you #Include <Array.au3> $String = "me,you,them,ours" $Result = StringSplit($string, ",") _ArrayDisplay($Result) Link to comment Share on other sites More sharing options...
diikee Posted July 28, 2008 Author Share Posted July 28, 2008 (edited) - save the string [csv] to a file instead of hard coding it. - open the file - read the file - stringsplit [ ","] - write the split values to a file or to console as a test. Edited July 28, 2008 by diikee Link to comment Share on other sites More sharing options...
herewasplato Posted July 28, 2008 Share Posted July 28, 2008 _FileReadToArray only splits on CR, LF, or CRLF - not commas try this code #include <Array.au3> $file = FileOpen("e.csv", 0) $sFile = FileOpen("Test1.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $aRecords = StringSplit(FileRead("e.csv"), ",") For $x = 1 To $aRecords[0] FileWriteLine($sFile, $aRecords[$x]) Next FileClose($file) FileClose($sFile) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 28, 2008 Moderators Share Posted July 28, 2008 _FileReadToArray only splits on CR, LF, or CRLF - not commas try this code #include <Array.au3> $file = FileOpen("e.csv", 0) $sFile = FileOpen("Test1.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $aRecords = StringSplit(FileRead("e.csv"), ",") For $x = 1 To $aRecords[0] FileWriteLine($sFile, $aRecords[$x]) Next FileClose($file) FileClose($sFile)FileWrite("Test.txt", StringReplace(FileRead("e.csv"), ",", "," & @CRLF)) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted July 28, 2008 Share Posted July 28, 2008 FileWrite("Test.txt", StringReplace(FileRead("e.csv"), ",", "," & @CRLF))minimalist :-) :-) :-) :-) :-) [size="1"][font="Arial"].[u].[/u][/font][/size] Link to comment Share on other sites More sharing options...
diikee Posted July 28, 2008 Author Share Posted July 28, 2008 woowwwwwwwwwwwwwwww ---that was easy. How comes other methods above couldn't work???? Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 28, 2008 Moderators Share Posted July 28, 2008 woowwwwwwwwwwwwwwww ---that was easy.How comes other methods above couldn't work????What are you referring to that worked and didn't work? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
diikee Posted July 28, 2008 Author Share Posted July 28, 2008 FileWrite("Test.txt", StringReplace(FileRead("e.csv"), ",", "," & @CRLF)) vs #include <Array.au3> $file = FileOpen("e.csv", 0) $sFile = FileOpen("Test1.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $aRecords = StringSplit(FileRead("e.csv"), ",") For $x = 1 To $aRecords[0] FileWriteLine($sFile, $aRecords[$x]) Next FileClose($file) FileClose($sFile) Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted July 28, 2008 Moderators Share Posted July 28, 2008 FileWrite("Test.txt", StringReplace(FileRead("e.csv"), ",", "," & @CRLF)) vs #include <Array.au3> $file = FileOpen("e.csv", 0) $sFile = FileOpen("Test1.txt", 2) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $aRecords = StringSplit(FileRead("e.csv"), ",") For $x = 1 To $aRecords[0] FileWriteLine($sFile, $aRecords[$x]) Next FileClose($file) FileClose($sFile)Seems he didn't add the comma back in like I did. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
herewasplato Posted July 28, 2008 Share Posted July 28, 2008 ...i wantme,you,them,ours,There you go SmOke_N - givin' the OP precisely what is requested :-) [size="1"][font="Arial"].[u].[/u][/font][/size] 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