in reply to What's the best way to detect character encodings? (Redux)

I've heard that detecting encodings is a hard problem.
  • Comment on Re: What's the best way to detect character encodings? (Redux)

Replies are listed 'Best First'.
Re^2: What's the best way to detect character encodings? (Redux)
by Jim (Curate) on Jun 10, 2013 at 05:12 UTC

    It gets difficult when it's arbitrarily any "legacy" character encoding you're trying to detect. For that problem, fancy algorithms that use character frequencies, n-grams, dictionary look-ups, and other methods are required. But I'm able to factor out most of this complexity because I know that any text in a "legacy" single-byte encoding is ASCII/ISO-8859-1/Windows-1252. If it's not, then the damage I do converting it to UTF-8 will be what the provider of the text files deserves on-account-of-because she didn't provide me Unicode text as she was supposed to do in the first place.