How to detect the character encoding of a file ?

  • Thread starter Thread starter JB
  • Start date Start date
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
 
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
 
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
 
Back
Top