How to get ASCII value of string in C#

RBS picture RBS · Dec 30, 2008 · Viewed 443.9k times · Source

I want to get the ASCII value of characters in a string in C#.

If my string has the value "9quali52ty3", I want an array with the ASCII values of each of the 11 characters.

How can I get ASCII values in C#?

Answer

Brig Lamoreaux picture Brig Lamoreaux · Dec 30, 2008

From MSDN

string value = "9quali52ty3";

// Convert the string into a byte[].
byte[] asciiBytes = Encoding.ASCII.GetBytes(value);

You now have an array of the ASCII value of the bytes. I got the following:

57 113 117 97 108 105 53 50 116 121 51