CyberFunk Productions Posted July 10, 2004 Posted July 10, 2004 i really don't understand how to parse files. Heres what i want to do. lets say I want to parse a text file and look for the word 'birthday', then display what line its on, is this possible?, and how would i go about doing it, i've read up on a little but i don't get it.
pekster Posted July 10, 2004 Posted July 10, 2004 Here are pieces you will need and what they do:FileOpen returns a file pointer to a fileFileReadLine reads a requested line from a fileWhile loops while a condition is trueExitLoop escapes a loopStringInStr finds a substring in a stringMsgBox display a message to the userWe can combine them like this:$serach = "my serach string" $file = FileOpen("C:\my_textfile.txt") If $file = -1 Then;error opening file MsgBox(0, "Fatal error", "Unable to open file... quitting") Exit EndIf $i = 1;set the line counter variable While 1 $line = FileReadLine($file, $i);get the current line and store to a var If @error Then ExitLoop;EOF reached with no success If StringInStr($line, $search) Then;we found the text, so tell user and exit MsgBox(0, "Text found", "The requested text was found on line " & $i) Exit EndIf $i = $i + 1 WEnd MsgBox(0, "Text not found", "Sorry, your requested text was not found on any line") [font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.
CyberFunk Productions Posted July 10, 2004 Author Posted July 10, 2004 wow, thats awsome, thanx, i'll work with this. It makes more sense now.
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