Converting Char to ASCII

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. :(
 
C

Chris Taylor

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
 
J

jasonkester

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/
 
J

Joerg Jooss

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,
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top