Jump to content
Sign in to follow this  
tAKTelapis

regular expression finding a line in a text doc

Recommended Posts

tAKTelapis

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

Share this post


Link to post
Share on other sites
Briegel

Try this line in ypour script.

$var = StringRegExp($Line, ('<a href="/cartoons/\?id=19971117">'), 0)oÝ÷ Øêæk&Þjëh×6$var = StringRegExp($Line, '(<a href="/cartoons/\?id=19971117">)', 0)
Edited by Briegel

Share this post


Link to post
Share on other sites
tAKTelapis

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

Share this post


Link to post
Share on other sites
Briegel

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'.

Share this post


Link to post
Share on other sites
tAKTelapis

thankyou very much for all of your help, my script is now complete.

thanks again.

/tAK

ps: happy SAAD for tomorrow to all other sys admins out there :whistle:

Edited by tAKTelapis

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.