I have an int and I want to display the associate letter. For example, if the int is "1", I want to display "a".
I have a variable "word" and I want to add this letter in it. This is my code :
word += (i+96).ToString();
Console.WriteLine(word);
But in the console, I have a list of number. I found Encoding.ASCII.GetChars
but it wants a byte
in parameter. How should I do please ?
You can use one of these methods to convert number to an ASCII / Unicode / UTF-16 character:
You can use these methods convert the value of the specified 32-bit signed integer to its Unicode character:
char c = (char)65;
char c = Convert.ToChar(65);
But, ASCII.GetString
decodes a range of bytes from a byte array into a string:
string s = Encoding.ASCII.GetString(new byte[]{ 65 });
Keep in mind that, ASCIIEncoding
does not provide error detection. Any byte greater than hexadecimal 0x7F is decoded as the Unicode question mark ("?").
So, for your solving your problem you can use one of these methods, for example:
word += (char)(i + 96);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With