Jump to content

Trying to read a line from a file that is over 65534 characters, can it be done?


Recommended Posts

Hi,

I am Trying to read a line from a file,

the line contains over 65534 characters.

Can it be done?

when i do the filereadline command it only returns the first 65534. is there anyway round this? other than perhaps using fileread??!

Thanks for taking the time to help me :whistle:

Example:

$test = ""
for $i = 1 to 65600
    $test &= "c"
next
$test &= " the end"
msgbox (0, "string len before write",stringlen($test) & @CRLF & "last 7 char in string:"& stringright($test,7))

FileDelete("C:\boomingrannytest.txt")
$x = fileopen ("c:\boomingrannytest.txt",1)
    FileWriteLine ($x,$test)
FileClose  ($x)
$x = fileopen ("c:\boomingrannytest.txt",0)
    $test = FileReadLine ($x)
FileClose  ($x)

msgbox (0, "string len after write/read",stringlen($test) & @CRLF & "last 7 char in string:"& stringright($test,7))
FileDelete("C:\boomingrannytest.txt")

the weird thing is the filewriteline allows me to write more than 65534 chars (try opening the c:\boomingrannytest.txt file when the string len after write/read message box is up - see the "the end" text is there!), but the filereadline doesn't read more than 65534 :lmao:

Edited by boomingranny
Link to comment
Share on other sites

;Create a dummy file with a string length twice what file read line returns
$chrs = 65534 * 2

$string= ""
For $j = 1 to 20

    For $i = 1 to $chrs
        $String &= "a"
    Next
$String &= @CRLF
Next

FileWrite("myfile.txt",$string)

;Read the whole file into a variable
$fileasaWhole = FileRead("myfile.txt")

;Split the file into an array by the @crlf at the end of line
$fileasaarray = StringSplit($fileasaWhole,@CRLF,1)

;loop through each line in the file which is now in an array
For $i = 1 to Ubound($fileasaarray) - 1
    Msgbox(0,"","Line " & $i & " Is " & StringLen($fileasaarray[$i]) & " Charachters long");you can do whatever you want with the data here
Next

This is the bit you really interested in

;Read the whole file into a variable
$fileasaWhole = FileRead("myfile.txt")

;Split the file into an array by the @crlf at the end of line
$fileasaarray = StringSplit($fileasaWhole,@CRLF,1)

;loop through each line in the file which is now in an array
For $i = 1 to Ubound($fileasaarray) - 1
    Msgbox(0,"","Line " & $i & " Is " & StringLen($fileasaarray[$i]) & " Charachters long");you can do whatever you want with the data here
Next
Edited by ChrisL
Link to comment
Share on other sites

so im just going to have to load the whole file into an array??

Problem is the file im working with is quite a whopper, hence the huge lines (some 65535+ in length)

Thanks heaps for your speedy reply!

i think there is also a _FileReadToArray which does a similar thing?

Edited by boomingranny
Link to comment
Share on other sites

so im just going to have to load the whole file into an array??

Problem is the file im working with is quite a whopper, hence the huge lines (some 65535+ in length)

Thanks heaps for your speedy reply!

i think there is also a _FileReadToArray which does a similar thing?

Yes there is, it pretty much does the same thing.

Once you have read the whole file in which you'd only need to do once I think your script will be subsiquently much quicker because you just reffer back to the array from then on

Link to comment
Share on other sites

Yes, reading file from memory rather than disk is working out quite well, i just did a quick rewrite of my script (aprox 1300 lines with several functions) and i think its running faster, although its hard to tell...

Thanks again for your help!

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