Jump to content

search after a word


Recommended Posts

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
Link to comment
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.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...