简体   繁体   中英

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. How can I get a string containing the ASCII characters from the Unicode value?

如果您有一个字符串实例,并且想要将其转换为包含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 .

使用Encoding.Convert方法

string text = "your text";
byte[] asciiBytes = Encoding.Convert(Encoding.Unicode, Encoding.ASCII, Encoding.Unicode.GetBytes(text));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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