Can I get the encoding of a text file?

M

MattB

Is there a way to determine the encoding of a text file (like is it
UTF-8 or something else?). I've been fishing around and can't find
anything but it seems like something that should be in there somewhere.
Thanks!
 
M

Mythran

MattB said:
Is there a way to determine the encoding of a text file (like is it UTF-8
or something else?). I've been fishing around and can't find anything but
it seems like something that should be in there somewhere. Thanks!

You can try the following:

Dim sr As StreamReader = New StreamReader("filename.txt", True)
Dim enc As Encoding = fs.CurrentEncoding()

HTH,
Mythran
 
J

Joerg Jooss

Mythran said:
You can try the following:

Dim sr As StreamReader = New StreamReader("filename.txt", True)
Dim enc As Encoding = fs.CurrentEncoding()

Well, Matt can try, but won't be that happy with the results.

Only a small set of encodings -- especially Unicode Transformation
Formats -- uses preambles or byte order marks from which you can infer
the encoding. Thus, the problem can be solved for a few special cases,
but not for the general case where the text file could be using any
kind of character encoding.

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top