Get Ascii value of a character

S

Sammut

Hi
I am using the following

Text = Convert.ToChar(67).ToString() & this will give a "C"

How can I do the opposite that is pass a "C" and an integer value is returned.

Thanks

Ivan Sammut
 
J

Jon Skeet [C# MVP]

Sammut said:
I am using the following

Text = Convert.ToChar(67).ToString() & this will give a "C"

How can I do the opposite that is pass a "C" and an integer value is returned.

The above is pretty unnecessary, to be honest. You can get away without
Convert - just cast:

char c = (char)67;
string s = c.toString();

and the other way round:

string s = "C";
char c = s[0]; // First character in s
int i = c; // i=67 now
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top