Jump to content

Recommended Posts

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.

Share this post

Link to post
Share on other sites

Here are pieces you will need and what they do:

  • FileOpen returns a file pointer to a file
  • FileReadLine reads a requested line from a file
  • While loops while a condition is true
  • ExitLoop escapes a loop
  • StringInStr finds a substring in a string
  • MsgBox display a message to the user
We 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")
$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)
  $i = $i + 1
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.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...