Jump to content

regular expression finding a line in a text doc


Recommended Posts

well, ive been working on this for near 3 hours. (i know its sloppy, but im just starting out with autoIT)

ive viewed all of the help topics etc, so far, i havent managed to get it to work.

i used the expressions checker included with the help file in the BETA to get the expression right. but i cant get my script to function.

here is my script:

$file = FileOpen("c:\Test.txt", 0)

While 1
    $Line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $var = StringRegExp($Line, (<a href="/cartoons/\?id=19971117">), 0)
; i think something is missing here, some kind of if...endif statement? (comment only added for forums.)
    MsgBox(0, "New Message", $var&" The line was found")
Wend

i read something in the script about not scanning lines in this manner, as it is cpu hungy.

eventually, when i find the line, i want to bring the ENTIRE line into a variable for use, i havent looked into doing this yet, so i figured i would ask.

anyways. any help appreciated.

/tAK

Link to post
Share on other sites

wikid.

thanks briegel. didnt think id get a response that fast.

it finds what im after. any ideas on making it identify the line number it was found on, and the Character number of the first character?

i do realise that the piece of code in its current state doesnt actually complete, and that the OK prompt just keeps coming, however this is not important at this time.

Cheers

/tAK

Link to post
Share on other sites

wikid.

thanks briegel. didnt think id get a response that fast.

it finds what im after. any ideas on making it identify the line number it was found on, and the Character number of the first character?

i do realise that the piece of code in its current state doesnt actually complete, and that the OK prompt just keeps coming, however this is not important at this time.

Cheers

/tAK

$file = FileOpen("c:\Test.txt", 0)

$i = 1 ; count the lines
While 1
    $Line = FileReadLine($file)
    If @error = -1 Then ExitLoop
    $var = StringRegExp($Line, ('<a href="/cartoons/\?id=19971117">'), 0)
    MsgBox(0, "New Message", $var&" Was found at Line " & $i )
    If $var = 1 Then ExitLoop
    $i += 1
WEnd

Sorry I don't understand 'the Character number of the first character'.

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...