473,387 Members | 1,553 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,387 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 1053
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.