简体   繁体   English

如何将Unicode值转换为ASCII字符串?

[英]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方法。

Take a look at this example here 看看这个例子在这里

You would need to covert it by transforming the string into a byte array . 您需要通过将字符串转换为byte array来转换它。

使用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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM