How To Convert A Number To an ASCII Character?

后端 未结 6 1170
礼貌的吻别
礼貌的吻别 2020-12-17 09:45

I want to create an application where user would input a number and the program will throw back a character to the user.

Edit: How about vice versa, changing a ascii

6条回答
  •  醉酒成梦
    2020-12-17 10:12

    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); 
    

    Also, 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 ("?").

提交回复
热议问题