How to automatically detect the codec text file?
General and Desktop
16
Posts
4
Posters
13.3k
Views
1
Watching
-
"EBCDIC":http://en.wikipedia.org/wiki/EBCDIC :-P
-
Unfortunately, the byte order marks in UTF-8 or UTF-16 are valid 8bit ASCII code points too.
UTF-8
BOM = EF BB BF =  (in ISO-8859-1 = Latin-1)UTF-16:
Big Endian BOM = FE FF = þÿ
Little Endian BOM = FF FE = ÿþUsing other ASCI code pages just yields other valid screen representations.
While having these three or two bytes as the very first bytes in a file is a strong sign of the use of unicode in the respective file, it is neither necessary (there is no mandatory BOM) nor sufficient to identify a UTF-8/16 encoded file.
If it was so easy to detect a file's encoding, there wouldn't be so much software that fails miserably on that job...