Convert/Save ANSI encoded-file to UTF-8

CygNuS

Well-known member
Joined
Aug 21, 2006
Messages
89
Location
Belgium
Programming Experience
Beginner
I have a txt file that i have to read.
Unfortunately it is encoded in ANSI and it contains a special character 'Ø' which my streamreader (i've tried all encodings) simply won't read.

If i manually save my ANSI txt to UTF-8 encoding and try again, it works perfectly.

But i need to automate this, anyone has any idea how to convert an existing txt to another encoding? (problem is: I must be able to do that without having to read the contents or 'Ø' is lost)
 
That did the trick, thanks!

Encoding.Default was the only encoding i thought i didn't need to try lol, and this is why:

I must say vb.net is kind of confusing at that point, one would think Encoding.Default would be the encoding that the streamreader uses when you don't specify it (that's what 'default' means everywhere, right?), but apparently it doesn't.

VB.NET:
Dim srIn As IO.StreamReader = New IO.StreamReader(myFile)
-> uses UTF-8 encoding

and

VB.NET:
Dim srIn As IO.StreamReader = New IO.StreamReader(myFile, System.Text.Encoding.Default)
-> uses ANSI-encoding
 
Back
Top