Sign in to follow this  
Followers 0
TheBobynator

search after a word

3 posts in this topic

#1 ·  Posted (edited)

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



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

thx very much :)

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  
Followers 0