ReadFile issue with Unicode and UTF-8
Posted: Wed Dec 02, 2015 1:31 am
What's happening is any unicode or UTF-8 text file created by notepad leaves some sort of extra character at the beginning of the file.
When the files are opened in Purebasic the first line is read incorrectly.
At first I assumed this was a problem with notepad, but I have also tested unicode files created with wordpad. The result was the same as notepad.
This problem doesn't exist if the files were created by Purebasic. Which I can live with in most cases, but now I have a text file that at times will be edited by an end user.
Which is a problem because after they edit the file it is no longer readable because of the first line.
I'm running Windows 7 Professional.
Any help on why this is happening would be greatly appreciated.
Here are the notepad files that I have been testing.
ReadFile.zip
And the code I've been using to read them.
When the files are opened in Purebasic the first line is read incorrectly.
At first I assumed this was a problem with notepad, but I have also tested unicode files created with wordpad. The result was the same as notepad.
This problem doesn't exist if the files were created by Purebasic. Which I can live with in most cases, but now I have a text file that at times will be edited by an end user.
Which is a problem because after they edit the file it is no longer readable because of the first line.
I'm running Windows 7 Professional.
Any help on why this is happening would be greatly appreciated.
Here are the notepad files that I have been testing.
ReadFile.zip
And the code I've been using to read them.
Code: Select all
Define.s Result$
If ReadFile(0, "Unicode File.txt")
Debug "UNICODE FILE"
While Eof(0) = 0
Result$ = ReadString(0, #PB_Unicode)
Debug Result$
If Result$ = "Line 1"
Debug "Line 1 is OK"
EndIf
Wend
CloseFile(0)
Else
MessageRequester("Information","Couldn't open the Unicode File!")
EndIf
Debug ""
If ReadFile(0, "ANSI File.txt")
Debug "ANSI FILE"
While Eof(0) = 0
Result$ = ReadString(0, #PB_Ascii)
Debug Result$
If Result$ = "Line 1"
Debug "Line 1 is OK"
EndIf
Wend
CloseFile(0)
Else
MessageRequester("Information","Couldn't open the ANSI File!")
EndIf
Debug ""
If ReadFile(0, "UTF8 File.txt")
Debug "UTF8 FILE"
While Eof(0) = 0
Result$ = ReadString(0, #PB_UTF8)
Debug Result$
If Result$ = "Line 1"
Debug "Line 1 is OK"
EndIf
Wend
CloseFile(0)
Else
MessageRequester("Information","Couldn't open the UTF8 File!")
EndIf