So I cast the int number 250 to a char, and initially was confused why the corresponding ASCII didn’t appear when I did printed it, but then realised it seemed to be using UTF instead?
From what I understand 0-127 map to the same in ASCII and UTF, but I want to use some ascii characters that are higher than that. Is there a way I can do this?
Any advice appreciated. Thanks
.NET uses UTF-16 for char
and string
.
ASCII is a 7-bit encoding, characters 0-127 are the only ASCII there is. There are other single byte encodings based on ASCII that are sometimes confused with ASCII, most commonly one of the Windows code pages or ISO 8859 variants.
You can use System.Text.Encoding to convert to and from various text encodings.
Encoding.ASCII.GetString
should do what you expect
thanks
I just did (char)250
and got ú
yes thats utf not ascii
ú as in:
úúúhh…thats an únexpected character
See: https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-encoding
.Net uses UnicodeEncoding by default. You’ll probably have to manually encode the char to a string using ASCIIEncoding.
var yourString = new string(Encoding.ASCII.GetChars(yourCharByteArray));
thanks