wakummaci 0 Posted October 23, 2010 Hi guys! I've figured a way out how to get a specific text between 2 specific characters/words, using stringbetween. (I'm gathering email adresses by the way.) My problem is, that stringbetween returns a one column one line string, which I can display with stringdisplay, but how do I write the content of it to a file? Filewriteline only writes 0s in my txt, and I can't refer to $temp as an array. Here is the simple code: #include <String.au3> #include <Array.au3> $file = FileOpen("test.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $file2 = FileOpen("test2.txt", 1) If $file2 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $temp = _StringBetween($line, 'mailto:', '"') ;_ArrayDisplay($temp, 'Default Search') <----- Using this line I can see the email adresses, but the line under this one only writes 0s in the txt file. FileWriteLine($file2, $temp & @CRLF) Wend FileClose($file) FileClose($file2) Thanks for your help in advance Share this post Link to post Share on other sites
wakummaci 0 Posted October 23, 2010 Hi guys! I've figured a way out how to get a specific text between 2 specific characters/words, using stringbetween. (I'm gathering email adresses by the way.) My problem is, that stringbetween returns a one column one line string, which I can display with stringdisplay, but how do I write the content of it to a file? Filewriteline only writes 0s in my txt, and I can't refer to $temp as an array. Here is the simple code: #include <String.au3> #include <Array.au3> $file = FileOpen("test.txt", 0) If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $file2 = FileOpen("test2.txt", 1) If $file2 = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop $temp = _StringBetween($line, 'mailto:', '"') ;_ArrayDisplay($temp, 'Default Search') <----- Using this line I can see the email adresses, but the line under this one only writes 0s in the txt file. FileWriteLine($file2, $temp & @CRLF) Wend FileClose($file) FileClose($file2) Thanks for your help in advance Nvm, just found arraytostring function... it didn't show up in the help file when I searched it. Share this post Link to post Share on other sites
engjcowi 1 Posted October 25, 2010 Hi I just tried your script as im trying to do somethign similar and when i use arraydisplay it works fine however when i used _arraytostring($temp) it still shows as zero. can you tell me what you did please? Drunken Frat-Boy Monkey Garbage Share this post Link to post Share on other sites
sshrum 1 Posted October 25, 2010 (edited) Doing a file write every time you do a line isn't efficient. the example I have below builds an array out of the input file, steps thru the array, does the evaluation, adds it to a storage variable, and then writes the variable to the output in one call when it's done: $sLine = "" $aEmail = FileReadtoArray("input.txt") for $i = 1 to $aEmail[0] $sLine &= _StringBetween($aEmail[$i], 'mailto:', '"') & @CRLF next FileWrite("output.txt") BTW, this code if off the top of my head, no error checking, and is not tested so it may choke but it should be good enough for ya to get going. Edited October 25, 2010 by sshrum Sean Shrum :: http://www.shrum.netAll my published AU3-based apps and utilities'Make it idiot-proof, and someone will make a better idiot' Share this post Link to post Share on other sites
engjcowi 1 Posted November 5, 2010 Hi Thanks Ill look at it shortly jamie Drunken Frat-Boy Monkey Garbage Share this post Link to post Share on other sites