Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get character for a given ascii value

Tags:

c#

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

like image 223
Dunc Avatar asked Jan 10 '11 16:01

Dunc


People also ask

How do I get ascii characters?

The most basic and easy way to extract the character from an ASCII Code is to cast the ASCII code to a char directly; this will convert the asciiValue of the int type to a char type.

How do I print a character using ASCII value?

Try this: char c = 'a'; // or whatever your character is printf("%c %d", c, c); The %c is the format string for a single character, and %d for a digit/integer. By casting the char to an integer, you'll get the ascii value.

What function can be used to get the ASCII value of a given character?

Using the chr () function, the character that represents the corresponding ASCII code can be obtained.


1 Answers

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.

like image 146
Jon Skeet Avatar answered Oct 05 '22 06:10

Jon Skeet