How to get ASCII value of string in C#

How to get ASCII value of string in C#

回答1

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

 

回答2

string s = "9quali52ty3";
foreach(char c in s)
{
  Console.WriteLine((int)c);
}

 

posted @ 2021-10-28 16:40  ChuckLu  阅读(5)  评论(0编辑  收藏  举报