There are a million posts on here on how to convert a character to its ASCII value.
Well I want the complete opposite.
I have an ASCII value stored as an int and I want to display its ASCII character representation in a string.
i.e. please display the code to convert the int 65
to A
.
What I have currently is String::Format("You typed '{0}'", (char)65)
but this results in "You typed '65'"
whereas I want it to be "You typed 'A'"
I am using C++/CLI but I guess any .NET language would do...
(edited post-humously to improve the question for future googlers)
Very simple. Just cast your char as an int . char character = 'a'; int ascii = (int) character; In your case, you need to get the specific Character from the String first and then cast it.
The Chr function in VB.NET converts the integer back to the character: Dim i As Integer = Asc("x") ' Convert to ASCII integer. Dim x As Char = Chr(i) ' Convert ASCII integer to char.
Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.
For ASCII values, you should just be able to cast to char? (C#:)
char a = (char)65;
or as a string:
string a = ((char)65).ToString();
In C++:
int main(array<System::String ^> ^args)
{
Console::WriteLine(String::Format("You typed '{0}'", Convert::ToChar(65)));
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With