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
Sorry I dont know Java, but I was faced with the same problem tonight, so I wrote this (it's 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;
}
Simply Try this:
int n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("data is: {0}", Convert.ToChar(n));
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.