RBS*_*RBS 97 c# encoding ascii
我想在C#中获取字符串中ASCII字符的值.
如果我的字符串具有值"9quali52ty3",我想要一个具有11个字符中每个字符的ASCII值的数组.
如何在C#中获取ASCII值?
小智 183
来自MSDN
string value = "9quali52ty3";
// Convert the string into a byte[].
byte[] asciiBytes = Encoding.ASCII.GetBytes(value);
您现在拥有字节的ASCII值数组.我得到以下内容:
57 113 117 97 108 105 53 50 116 121 51
Lep*_*R64 32
string s = "9quali52ty3";
foreach(char c in s)
{
  Console.WriteLine((int)c);
}
jas*_*son 21
这应该工作:
string s = "9quali52ty3";
byte[] ASCIIValues = Encoding.ASCII.GetBytes(s);
foreach(byte b in ASCIIValues) {
    Console.WriteLine(b);
}
你的意思是你只想要字母字符而不是数字吗?那么你想要"质量"吗?您可以使用Char.IsLetter或Char.IsDigit逐个过滤它们.
string s = "9quali52ty3";
StringBuilder result = new StringBuilder();
foreach(char c in s)
{
  if (Char.IsLetter(c))  
    result.Add(c);
}
Console.WriteLine(result);  // quality
string text = "ABCD";
for (int i = 0; i < text.Length; i++)
{
  Console.WriteLine(text[i] + " => " + Char.ConvertToUtf32(text, i));
}
如果我没记错的话,ASCII 值是Unicode数字的低七位的数字。
| 归档时间: | 
 | 
| 查看次数: | 397004 次 | 
| 最近记录: |