How to detect the character encoding of a file ?

J

JB

Hi All,

I have an application that reads text files and does various things
with their content.
I'd like to know how to detect the character encoding of each text
file so my app can handle them correctly (e.g. ANSI, UTF8, etc).

Thanks for any tips
JB
 
M

Mattias Sjögren

I have an application that reads text files and does various things
with their content.
I'd like to know how to detect the character encoding of each text
file so my app can handle them correctly (e.g. ANSI, UTF8, etc).

The StreamReader class already has some support for this, check out
the contructors that take a boolean detectEncodingFromByteOrderMarks
parameter.


Mattias
 
M

Michel Posseth [MCP]

Also note that a lot of older systems will refuse files because they can`t
handle the BOM at the begining of the file
because of this reasson there are a lot of files still out there without
BOM .

michel
 

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

Top