rkr Posted February 11, 2018 Share Posted February 11, 2018 Hi, i am having a text file which has over 14000lines, i am using the following code (only part presented below) to search a string. the code is working, but this is taking lot of time, is there a better way to read and find the string For $i= 0 to $tot_lines ; $tot_lines is the total numbers of lines in file $read = filereadtoarray("file.txt") if $read[$i]=$search then ; $search is defined as the string to search $line_found=$i endif next could some one please assist, thanks Link to comment Share on other sites More sharing options...
czardas Posted February 11, 2018 Share Posted February 11, 2018 (edited) You place FileReadToArray() inside the loop: that's wrong in this case. Try this: Local $aRead = FileReadToArray("file.txt") Local $line_found = -1 Local $search = "hello world" ; Type your own search here term instead. For $i = 0 to UBound($aRead) -1 ; UBound($aRead) -1 is the total numbers of lines in file If $aRead[$i] = $search Then ; $search is defined as the string to search $line_found = $i ExitLoop ; unless you want to find all matches (requires a different approach) EndIf Next If $line_found > -1 Then ConsoleWrite($aRead[$line_found] & @LF) Edited February 11, 2018 by czardas operator64 ArrayWorkshop 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