Converting Char to ASCII

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
In old asp I would just juse ASC('a') and that would give me the ASCII code
of that character, How can I do this in ASP.net

Having trouble finding the right class. :(
 
Hi,

You did not specify the language so I will assume C#, a simple cast will do
the job
int c = (int)'a';
You can also use the Convert class
int c = Convert.ToInt32('a');

For VB.NET the Convert class will work or you can use the VB.NET
implementation of Asc().

Hope this helps
 
Don't forget the usual caveat that the above only works for ASCII
values between 1 and 127. Above that, and into Unicode, all bets are
off.

This doesn't matter for most practical applications, but do some
digging in this group for some amusing theological battles on this
topic.

Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
 
Chris said:
Hi,

You did not specify the language so I will assume C#, a simple cast
will do the job
int c = (int)'a';
You can also use the Convert class
int c = Convert.ToInt32('a');

For VB.NET the Convert class will work or you can use the VB.NET
implementation of Asc().

Hope this helps

This will return the character's Unicode codepoint, which is not
necessarily the same as the character's byte value in ANSI encoding --
whatever that's suppoed to be. Windows-1250? -1251? -1252?

To encode characters, use a appropriate System.Text.Encoding instance
instead

Cheers,
 
Back
Top