开发者

How can I convert a Unicode value to an ASCII string?

开发者 https://www.devze.com 2023-03-07 22:13 出处:网络
I am given a Un开发者_运维百科icode value that contains characters that can be represented as ASCII. How can I get a string containing the ASCII characters from the Unicode value?Take a look at this e

I am given a Un开发者_运维百科icode value that contains characters that can be represented as ASCII. How can I get a string containing the ASCII characters from the Unicode value?


Take a look at this example here

You would need to covert it by transforming the string into a byte array.


If you have an instance of a string and you want to turn it into an array of bytes containing the values for ASCII characters you can use the GetBytes method of the System.Text.ASCIIEncoding class.


Use the Encoding.Convert Method


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

精彩评论

暂无评论...
验证码 换一张
取 消