topten Posted May 7, 2016 Posted May 7, 2016 (edited) I have a script, where I need to read file line by line to a variable (80000 lines) takes it forever to do it. Is any way to make it faster? Local $hFileOpen = FileOpen($SelectFile, $FO_READ) $str = "" for $i = 1 to $num ; ~about 80000 lines Local $sFileRead = FileReadLine($hFileOpen, $i) $str = $str&$sFileRead next Great thanx in advance! Edited May 7, 2016 by topten
InunoTaishou Posted May 7, 2016 Posted May 7, 2016 What kind of data are you trying to read from the file? Why are you doing it a line at at time when you're just appending it to a string without the line feed? Local $hFileOpen = FileOpen($SelectFile, $FO_READ) Local $sStr = "" If ($hFileOpen) Then $sStr = StringRegExpReplace(FileRead($hFileOpen), "[\r\n]", "") FileClose($hFileOpen) EndIf This will do the same thing.
Developers Jos Posted May 7, 2016 Developers Posted May 7, 2016 How much faster is this version for you? Local $hFileOpen = FileOpen($SelectFile, $FO_READ) $str = "" for $i = 1 to $num ; ~about 80000 lines $str&= FileReadLine($hFileOpen) next Or else try this: Local $str = FileRead($SelectFile) $str = StringReplace($str,@crlf,"") Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
topten Posted May 7, 2016 Author Posted May 7, 2016 Great thanx InunoTaishou, Trong, Jos ! It works now much better On 5/7/2016 at 4:57 PM, Jos said: How much faster is this version for you? Local $hFileOpen = FileOpen($SelectFile, $FO_READ) $str = "" for $i = 1 to $num ; ~about 80000 lines $str&= FileReadLine($hFileOpen) next This one is say, 3-5 times faster than mine Or else try this: Local $str = FileRead($SelectFile) $str = StringReplace($str,@crlf,"") This one is about 20-30 times faster than mine Expand
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