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));
精彩评论