Jump to content
avechuche

Problem with FileRead/FileOpen

Recommended Posts

avechuche

Hello. I have a ".txt" file that X number of lines at the end of each line has a character that if opened with Windows Notepad, seems a blank, but if you open it with Notepad ++, a character "NULL" . The problem is that when I make a FileRead, just read me until the first NULL. Is there any way to fix it? Thanks!

Share this post


Link to post
Share on other sites
232showtime

let me give you a piece of advice, post your code so expert coders can analyze your script.


ill get to that... i still need to learn and understand a lot of codes graduated.gif

Correct answer, learn to walk before you take on that marathon.

Share this post


Link to post
Share on other sites
avechuche

This code 

$sFile = FileRead("Example.txt")

Return only first line :S

But if I use a loop + FileReadLine, it works perfectly, but I need to process data faster that read line by line.

Example.txt

Edited by avechuche

Share this post


Link to post
Share on other sites
AspirinJunkie

The file contains Null-Chars (a char with the value 0). A text file is ending at this char. So if you handle the file as a text file, the file only gets read until the first Null.

But because the file contains text information anyway i would say the file ist corrupt - because a Null-character has no place inside a text file.

The solution: Handle the file as a binary file and kill the Null-chars:

$hFile = FileOpen("Example.txt", 16)
$sFile = StringReplace(BinaryToString(FileRead($hFile)), Chr(0), "", 0, 1)
FileClose($hFile)

ConsoleWrite($sFile)

 

  • Like 1

Share this post


Link to post
Share on other sites
avechuche

The file contains Null-Chars (a char with the value 0). A text file is ending at this char. So if you handle the file as a text file, the file only gets read until the first Null.

But because the file contains text information anyway i would say the file ist corrupt - because a Null-character has no place inside a text file.

The solution: Handle the file as a binary file and kill the Null-chars:

$hFile = FileOpen("Example.txt", 16)
$sFile = StringReplace(BinaryToString(FileRead($hFile)), Chr(0), "", 0, 1)
FileClose($hFile)

ConsoleWrite($sFile)

 

​Perfect!!! THX!

Share this post


Link to post
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

×