For example: ‘½’ or ASCII DEC 189. When I read the bytes from a text file the byte[] contains the valid value, in this case 189.
Converting to Unicode results in the Unicode replacement character 65533.
UnicodeEncoding.Unicode.GetString(b);
Converting to ASCII results in 63 or ‘?’
ASCIIEncoding.ASCII.GetString(b);
If this isn’t possible what is the best way to handle this data? I’d like to be able to perform string functions like Replace().
Byte 189 represents a ‘½’ in iso-8859-1 (aka ‘Latin-1’), so the following is maybe what you want:
All strings and chars in .NET are UTF-16 encoded, so you need to use an encoder/decoder to convert anything else, sometimes this is defaulted (e.g. UTF-8 for FileStream instances) but good practice is to always specify.
You will need some form of implicit or (better) explicit metadata to supply you with the information about which encoding.