获得一个字符的ASCII值在C#字符串 [英] Getting The ASCII Value of a character in a C# string
本文介绍了获得一个字符的ASCII值在C#字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
考虑字符串:
string str="A C# string";
什么是用C#打印输出str中每个字符的ASCII值最有效的方式。
What would be most efficient way to printout the ASCII value of each character in str using C#.
推荐答案
下面是一个选择,因为你不喜欢的演员为int:
Here's an alternative since you don't like the cast to int:
foreach(byte b in System.Text.Encoding.UTF8.GetBytes(str.ToCharArray()))
Console.Write(b.ToString());
这篇关于获得一个字符的ASCII值在C#字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文