Skip to content

Instantly share code, notes, and snippets.

@hoangtranwork
Created February 11, 2013 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hoangtranwork/4755010 to your computer and use it in GitHub Desktop.
Save hoangtranwork/4755010 to your computer and use it in GitHub Desktop.
how about a public gist with gister
private static Encoding DetectEncoding(byte[] inputBytes, int offset, int len)
{
var detector = new CharsetDetector();
detector.Feed(inputBytes, offset, len);
detector.DataEnd();
string result = detector.Charset;
Encoding encoding = Encoding.UTF8;
if (!string.IsNullOrEmpty(result) && detector.Confidence <= (double) DetectionConfidence.SureAnswer)
{
encoding = Encoding.GetEncoding(result);
}
return encoding;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment