ASCII values

D

Drew

I need to display the ASCII numeric values of each letter in a string.

I think strings are stored in unicode in C# (?)

I can convert the string to a char array but how do I get the ascii values
of each character?

Thanks,

Drew
 
D

Drew

Oh, it looks like I can just cast the char to an int.

Is that the best way to do this?

Drew
 
J

Jon Skeet [C# MVP]

Drew said:
Oh, it looks like I can just cast the char to an int.

Is that the best way to do this?

Yes, that's fine. Bear in mind that that will give you the Unicode
value, which will be the same as the ASCII value for all ASCII
characters. If you want to check whether or not it was actually an
ASCII character to start with, just check whether or not the value is
< 128.
 
M

Michael Giagnocavo [MVP]

Sure, just remember that many chars are not ASCII. So if you happen to get
any data above 127, then it's not ASCII.
-mike
MVP
 

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