How to find out the Encoding of a File? C# -
Well I have to find out that some of the files I found in some directories are either UTF 8 encoded or NNI Encoding is encoded to change something else I decide later on is my problem .. How can I find out if any file is UTF8 or ANSI encoded? Both encodings are actually true in my file.
There is no reliable way to do this, the file can be just random binary), though Windows Notepad The process made by the software is expanded into the blog of Michael S. Kaplan:
- Check the first two bytes; 1. If a UTF-16 is Bom, keep it as a "(Unicode") file (and load it); 2. If UTF-16 is BOM, then keep it as "(Unicode (Big Endion)" file (and load it); 3. If the first two bytes look like the beginning of a UTF-8 BOM , Then check the next byte and if we have UTF-8 BOM, then keep it as "(UTF-8") file (and load);
- Check with IsTextUnicode The function assumes that it is BOM-less UTF-16 LE, if it is, keep it as "(Unicode") file (and load it as);
- h To distribute whether it uses UTF-8 using the original RFC 22 9 9 definition from 1998, and if it is again (and loaded) as "UTF-8" file;
- Use the ANSI file to assume the machine's default system code page.
Now note that there are some holes here, such as BOM-less UTF in step 2 -16 BE (There is not quite good with that there can be a bug here, I am not sure - if it is so, no Which now has a bug in it beyond any bug in IsTextUnicode).
Comments
Post a Comment