Detect encoding of byte array C#
In short, no. Please see How to detect the character encoding of a text file? for a detailed answer on various encodings and why they can't be automatically determined.
Your best solution is to convert the string from it's original encoding to UTF8 and convert that to a byte array. Then you'll know your byte array's encoding...
I realize I'm late to the party here, but I just had a need to do this very thing and found a good way to do it:
byte[] data; // Populate this however you see fit with your datastring text;Encoding enc;using (StreamReader reader = new StreamReader(new MemoryStream(data), detectEncodingFromByteOrderMarks: true)){ text = reader.ReadToEnd(); enc = reader.CurrentEncoding; // the reader detects the encoding for you!}