Jump to content
Sign in to follow this  
TheBobynator

search after a word

Recommended Posts

TheBobynator

hi,

is it possible to search in a txt file after a word and then i get the line number of the word which i searched.

I search after the word mouse.

txt file__________________________________

dog

cat

hourse

mouse

rabbit

tiger

_______________________________________

now must get the line number "4"

help.

thx

Edited by TheBobynator

Share this post


Link to post
Share on other sites
Authenticity

Dim $sText = 'Cat' & @CRLF & 'Dog' & @CRLF & 'Giraffa' & @CRLF & 'Bird' & @CRLF & _
             'Mesocricetus' & @CRLF & 'Parrot' & @CRLF & 'Etc..'
             

Dim $aLines = StringRegExp($sText, '(?>[^\r]*)(?:\r\n|$)', 3)

For $i = 0 To UBound($aLines)-1
    If StringInStr($aLines[$i], 'Mesocricetus') Then ExitLoop
Next

ConsoleWrite('Found Mesocricetus on line: ' & $i+1 & @LF)

Use StringSplit if you like, the line is not zero based.

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.