compact21 Posted May 15, 2014 Share Posted May 15, 2014 Hi, i'm trying to find a certain string(word) in a big text file by using FileReadLine() but i can't loop to read each line from the first to the last one because the first line is 1 and the last is -1 and For...To...Step...Next with Step +1 doesn't work. i hope i made myself clear, the point is to have the line counting. $open=FileOpen("wordweb5.txt", 0) ; open the text file in read mode For $i = 1 To -1 Step +1 ; loop to read from the first line to the last $read = FileReadLine($open, $i) ; read from the first line to the last ToolTip($i,1,1) ; show counting If StringInStr($read, "europe!") = True Then MsgBox(Default, Default, $read&" found on line "&$i) ;MsgBox when String is found Next FileClose($open) ;close filehandle Exit Link to comment Share on other sites More sharing options...
JustSomeone Posted May 15, 2014 Share Posted May 15, 2014 Take a look at FileReadToArray and _ArraySearch functions, try them out and let's see Link to comment Share on other sites More sharing options...
jguinch Posted May 15, 2014 Share Posted May 15, 2014 You can use a simple While 1 loop : $hFile = FileOpen("file.txt") If $hFile = -1 Then Exit MsgBox(16, "", "error") $iCount = 0 While 1 $iCount += 1 $line = FileReadLine($hFile) If @error Then ExitLoop ToolTip($iCount,1,1) If StringInStr($line, "europe!") Then MsgBox(0, "", " ""europe! "" found on line " & $iCount) WEnd Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
compact21 Posted May 15, 2014 Author Share Posted May 15, 2014 both methods works great, thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now