Files
stgsharp/新建文本文档.txt
T

17 lines
810 B
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
你可以看到,ASCII编码只能表示0-127范围内的字符,所以超出这个范围的中文字符都被替换成了问号(63)。
如果你想用ASCII字符数组表示超出ASCII字符范围的字符的字节码,你可以先将字符串转换为一个UTF-8字节数组,然后再将每个字节转换为一个ASCII字符。例如:
string s = "你好,这是Bing。";
byte[] utf8Bytes = Encoding.UTF8.GetBytes(s);
char[] asciiChars = new char[utf8Bytes.Length];
for (int i = 0; i < utf8Bytes.Length; i++)
{
asciiChars[i] = (char)utf8Bytes[i];
}
Copy
这段代码会得到以下ASCII字符数组:
{ 'ä', '½', 'ä', '½', '¥', ',', ' ', 'è', '¿', 'æ', '˜', '¯', 'B', 'i', 'n', 'g', 'ã', '€', '‚' }
Copy
你可以根据自己的需要对这个数组进行处理或输出。