473,396 Members | 1,827 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ASCII values

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
6 6795
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
Convert.ToInt32();
Nov 16 '05 #3
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Dan | last post by:
Some knows how to verify an ascii code. I want to verify a char for the list of ascii codes between 64 to 122. Mainly in other words, check a char, look if its in a range of ascii code and output...
5
by: b.stewart | last post by:
I have only been using C++ for a few afternoons and i still get confused at nearly every line i type so maybe someone here can help me. Im trying to write a small program that can change a...
12
by: chunhui_true | last post by:
i have a class, it can read one line(\r\n ended) from string,when i read line from utf8 string i can't get any thing! maybe i should conversion utf8 to ascii??there is any function can conversion...
1
by: Kermit Piper | last post by:
Hello, I have a function that lets me convert one character and throw an alert with the corresponding ASCII value, but what I am having trouble with is applying it to a text box. What I'm trying...
7
by: Jeffrey Spoon | last post by:
Hello, I'm a bit stuck trying to convert a text file which contains extended ASCII text and changing the ASCII values so they become readable. I do this by subtracting 127 from the ASCII value....
17
by: Gregor KovaĨ | last post by:
Hi! Does DB2 handle extended ASCII table? Example: VALUES(CHR(65)) =A VALUES(CHR(129)) =null, but according to www.asciitable.com should be u with umlaut. Any idea ?
0
by: nmsreddi | last post by:
Hi friends I am working on serialport in c# ,i am using C#2005 i have successfully done the serial communication with GSM modem and able to send and receive data , the main problem ,the serial...
6
by: ssetz | last post by:
Hello, For work, I need to write a password filter. The problem is that my C+ + experience is only some practice in school, 10 years ago. I now develop in C# which is completely different to me....
4
by: meendar | last post by:
Hi, I am having a character pointer which contains ascii values. i just want to convert all these ascii values to respective characters and again store it in another character pointer. ...
9
by: =?Utf-8?B?RGFu?= | last post by:
I have the following code section that I thought would strip out all the non-ascii characters from a string after decoding it. Unfortunately the non-ascii characters are still in the string....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.