Hello.
Yes is a most frequent question, and this matter is vague for me and since i don't now much about it.
But i would like a very precise way to find a files Encoding. So precise as Notepad++ is.
Thanks.
Hello.
Yes is a most frequent question, and this matter is vague for me and since i don't now much about it.
But i would like a very precise way to find a files Encoding. So precise as Notepad++ is.
Thanks.
I'd try the following steps:
1) Check if there is a Byte Order Mark
2) Check if the file is valid UTF8
3) Use the local "ANSI" codepage (ANSI as Microsoft defines it)
Step 2 works because most non ASCII sequences in codepages other that UTF8 are not valid UTF8.
Since you reference notepad++ I'll assume you mean text files.
There is built-in support in the framework:
// detectEncodingFromByteOrderMarks=true
using (var r = new StreamReader(fileName, true))
{
var e = r.CurrentEncoding;
}