wakummaci Posted October 23, 2010 Share 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 Link to comment Share on other sites More sharing options...
wakummaci Posted October 23, 2010 Author Share 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. Link to comment Share on other sites More sharing options...
engjcowi Posted October 25, 2010 Share 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 Link to comment Share on other sites More sharing options...
sshrum Posted October 25, 2010 Share 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.net All my published AU3-based apps and utilities 'Make it idiot-proof, and someone will make a better idiot' Link to comment Share on other sites More sharing options...
engjcowi Posted November 5, 2010 Share Posted November 5, 2010 Hi Thanks Ill look at it shortly jamie Drunken Frat-Boy Monkey Garbage 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