Jump to content

Problem with FileRead/FileOpen


Recommended Posts

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!

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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!

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