How to get character for a given ascii value

后端 未结 9 2718
醉酒成梦
醉酒成梦 2020-11-29 05:51

How can I get the ascii character of a given ascii code.

e.g. I\'m looking for a method that given the code 65 would return \"A\".

Thanks

9条回答
  •  广开言路
    2020-11-29 06:23

    Do you mean "A" (a string) or 'A' (a char)?

    int unicode = 65;
    char character = (char) unicode;
    string text = character.ToString();
    

    Note that I've referred to Unicode rather than ASCII as that's C#'s native character encoding; essentially each char is a UTF-16 code point.

提交回复
热议问题