Jump to content

FileReadLine to Variable, any way do it faster? [solved]


Recommended Posts

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 by topten
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Developers

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.
  :)

Link to comment
Share on other sites

Great thanx  InunoTaishou,  Trong, Jos !

It works now much better :)

42 minutes ago, 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

 

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...