Detecting Encoding in C#

On a project that I’ve been working on recently, I was having some trouble combining SQL scripts that where in a couple of different formats.

While there’s no easy way to detect all of the possible encodings, by checking the byte order mark (BOM) there is a pretty straight forward way to detect the following encodings:

  • UTF-16
  • UTF-16BE
  • UTF-32
  • UTF-32BE
  • UTF-8

2 Responses to “ “Detecting Encoding in C#”

  1. Mike says:

    Thanks, really helpful

  2. Nice one! Cheers.