Get string data from encoded bytes

I have an array of bytes that comes from a barcode reader (connected via a COM port) that reads an ID card. When I convert them, I can read some data, for example:

Name, Surname, City

etc., but if some data has some characters like "Ë" or "Ç" or some characters that are used in our language [ed: OP in Pristina, Kosovo], I get "?". How can I get these characters through decoding?

+5
source share
1 answer

You need to know the appropriate Encodingone that uses the device; it can be, for example, UTF-16, in this case

string s = Encoding.Unicode.GetString(bytes);

or UTF-8:

string s = Encoding.UTF8.GetString(bytes);

/ :

string s = Encoding.GetEncoding(yourEncoding).GetString(bytes);
+9

All Articles