Invalid Characters in StringBuilder.ToString

stevecking

Active member
Joined
Dec 27, 2006
Messages
32
Programming Experience
5-10
I'm building an application compatible .MPX text file using a StringBuilder and writing it using My.Computer.FileSystem.WriteAllText(_FullPath, _MpxText, False). When I open the file using the application I get an application error. When I replace the first line (of 450+ lines) with a good first line from a previous working file the application opens the file perfectly. I've opened the file as a binary file and discovered 3 bytes (EF BB BF) which are not text but appear to be special characters. If I copy the text from the string variable prior to using WriteAllText and create a file manually, everything seems to work perfectly also. Any help with this issue would be appreciated.
 
theAnswer

I delayed working this problem for a while but I finally determined the answer. The code
My
.Computer.FileSystem.WriteAllText(_FullPath, _MpxText, False) put the three non-ASCII characters at the beginning of the file. The solution was simple but I'm learning as I go:
My
.Computer.FileSystem.WriteAllText(_FullPath, _MpxText, False, System.Text.Encoding.ASCII). The optional parameter solved the problem.

:D
 
Thanks JohnH. This completes my education for solving this issue. I checked out the Wikipedia article and recognized the translated characters for UTF-8.
 
Back
Top