By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,758 Members | 1,264 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,758 IT Pros & Developers. It's quick & easy.

ASCII values

P: n/a
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

Nov 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Oh, it looks like I can just cast the char to an int.

Is that the best way to do this?

Drew

Nov 16 '05 #2

P: n/a
Convert.ToInt32();
Nov 16 '05 #3

P: n/a
Drew <so*****@hotmail.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

P: n/a
Kleenex <an*******@discussions.microsoft.com> wrote:
Convert.ToInt32();


Why call a method when a simple cast (which could even be implicit)
works fine?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #5

P: n/a
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

"Drew" <so*****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
Oh, it looks like I can just cast the char to an int.

Is that the best way to do this?

Drew


Nov 16 '05 #6

P: n/a
The implicit cast works great.

I didn't know it was that easy. :)

Drew
"Michael Giagnocavo [MVP]" <mg*******@Atrevido.net> wrote in message news:uc**************@tk2msftngp13.phx.gbl...
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

"Drew" <so*****@hotmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl...
Oh, it looks like I can just cast the char to an int.

Is that the best way to do this?

Drew

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.