How to get character for given ascii value

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

eg. I am looking for a method that, given code 65, will return "A".

thank

+46
c #
Jan 10 '11 at 16:08
source share
7 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 mentioned Unicode, not ASCII, as this is coding in C #; essentially every char is a UTF-16 code point.

+102
Jan 10 2018-11-11T00:
source share
  string c = Char.ConvertFromUtf32(65); 

c will contain "A"

+28
Jan 10 '11 at 16:10
source share

This works in my code.

 string asciichar = (Convert.ToChar(65)).ToString(); 

Return: asciichar = 'A';

+3
Dec 18 '16 at 22:08
source share

It can also be done in another way.

 byte[] pass_byte = Encoding.ASCII.GetBytes("your input value"); 

and then print the result. using the foreach .

+1
Feb 25 '14 at 7:58
source share

Sorry, I don't know Java, but today I ran into the same problem, so I wrote this (this is in C #)

 public string IncrementString(string inboundString) { byte[] bytes = System.Text.Encoding.ASCII.GetBytes(inboundString.ToArray); bool incrementNext = false; for (l = -(bytes.Count - 1); l <= 0; l++) { incrementNext = false; int bIndex = Math.Abs(l); int asciiVal = Conversion.Val(bytes(bIndex).ToString); asciiVal += 1; if (asciiVal > 57 & asciiVal < 65) asciiVal = 65; if (asciiVal > 90) { asciiVal = 48; incrementNext = true; } bytes(bIndex) = System.Text.Encoding.ASCII.GetBytes({ Strings.Chr(asciiVal) })(0); if (incrementNext == false) break; // TODO: might not be correct. Was : Exit For } inboundString = System.Text.Encoding.ASCII.GetString(bytes); return inboundString; } 
0
Sep 02 '16 at 7:51 on
source share

I believe that a simple actor can work

int ascii = (int) "A"

-one
Jan 10 '11 at 16:11
source share

Here's a function that works for all 256 bytes, and ensures that you see a character for each value:

 static char asciiSymbol( byte val ) { if( val < 32 ) return '.'; // Non-printable ASCII if( val < 127 ) return (char)val; // Normal ASCII // Workaround the hole in Latin-1 code page if( val == 127 ) return '.'; if( val < 0x90 ) return "€.β€šΖ’β€žβ€¦β€ β€‘Λ†β€°Ε β€ΉΕ’.Ε½."[ val & 0xF ]; if( val < 0xA0 ) return ".''""β€’β€“β€”Λœβ„’Ε‘β€ΊΕ“.ΕΎΕΈ"[ val & 0xF ]; if( val == 0xAD ) return '.'; // Soft hyphen: this symbol is zero-width even in monospace fonts return (char)val; // Normal Latin-1 } 
-one
Feb 24 '17 at 11:28
source share



All Articles