[英]How can I convert a Unicode value to an ASCII string?
I am given a Unicode value that contains characters that can be represented as ASCII. 我被赋予一个Unicode值,其中包含可以表示为ASCII的字符。 How can I get a string containing the ASCII characters from the Unicode value? 如何从Unicode值中获取包含ASCII字符的字符串?
如果您有一个字符串实例,并且想要将其转换为包含ASCII字符值的字节数组,则可以使用System.Text.ASCIIEncoding类的GetBytes方法。
使用Encoding.Convert方法
string text = "your text";
byte[] asciiBytes = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, Encoding.Unicode.GetBytes(text));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.