I am trying to read log files into a String but sometimes the log file
doesn't contain encoding marks at the beginning of the file to indicate to
readers what kind of file it is (Unicode, UTF8 etc). For example, COM+.log
in the windows directory does not contain any encoding marks but the text is
written as Unicode. For these instances, what are good work-arounds to
auto-detect the log file as Unicode and read the file as a String?

Notepad.exe does this and I am wondering how they go about auto-detecting
the encoding when encoding marks do not exist. For example, if encoding
marks do not exist, do they just read the second byte in the file and if it
is zero assume the file is Unicode?

Thanks

RE: StreamReader.OpenText and Unicode by MattiasSjgren

MattiasSjgren
Wed Nov 09 03:16:16 CST 2005

>For these instances, what are good work-arounds to
> auto-detect the log file as Unicode and read the file as a String?

You can try using the IsTextUnicode API in advapi32.dll.


Mattias