Streamreader / Writer Encoding

ss7thirty

Well-known member
Joined
Jun 14, 2005
Messages
455
Location
New Jersey, US
Programming Experience
5-10
What type of encoding do I have to use to preserve the following characters:

ç , É

And the u with dots above it. I have tried a few different ways of going about this but none of the different encodings that I try preserve these letters. Some just truncate them and others replace them with a question mark.

What I am doing is reading from a text file using a streamreader and then outputting using a few different streamwriter object, essentially splitting up the first large text file. Upon doing this a few characters are being cut off or changed depending on the encoding that I use. How should I go about constructing the streamwriter and reader objects specifying the encoding. What is the best way to do this?
 
It really depends how the files were written in the first place. I would think that this should do the job:
VB.NET:
Dim reader As New IO.StreamReader("file path here", System.Text.Encoding.Unicode)
but if not then you can try UTF7, UTF8 and UTF32. If none of those work then you might also try each one with a third parameter. Specify True to detect byte-ordering from the file itself. It might be that you're using the correct encoding but you're reading the bytes the opposite way to how they were written:
VB.NET:
Dim reader As New IO.StreamReader("file path here", System.Text.Encoding.Unicode, True)
 
Back
Top