【问题标题】:Can someone explain Encoding.Unicode.GetBytes("hello") for me?有人可以为我解释 Encoding.Unicode.GetBytes("hello") 吗?
【发布时间】:2008-11-11 15:04:51
【问题描述】:

我的代码:

        string input1;

        input1 = Console.ReadLine();

        Console.WriteLine("byte output");

        byte[] bInput1 = Encoding.Unicode.GetBytes(input1);


        for (int x = 0; x < bInput1.Length; x++)
            Console.WriteLine("{0} = {1}", x, bInput1[x]);

输出:

104 0 101 0 108 0 108 0 111 0

对于输入“你好”

是否有对字符图的参考,我可以理解这一点?

【问题讨论】:

    标签: unicode


    【解决方案1】:

    您应该阅读http://www.joelonsoftware.com/articles/Unicode.html 上的“每个软件开发人员绝对、肯定必须了解 Unicode 和字符集(没有借口!)的绝对最低要求”

    您可以在http://www.unicode.org 找到所有 Unicode 字符的列表,但不要指望能够在不了解文本编码问题的情况下阅读那里的文件。

    【讨论】:

      【解决方案2】:

      http://www.unicode.org/charts/,您可以找到所有 Unicode 代码图表。 http://www.unicode.org/charts/PDF/U0000.pdf 表明“h”的代码点是 U+0068。 (查看这些数据的另一个好工具是BabelMap。)

      UTF-16 编码的确切细节可以在http://unicode.org/faq/utf_bom.html#6http://www.ietf.org/rfc/rfc2781.txt 找到。简而言之,U+0068 被编码(在 UTF-16LE 中)为 0x68 0x00。在十进制中,这是您看到的前两个字节:104 0。

      其他字符编码类似。

      最后,除了Unicode Standard 本身之外,一个很好的参考(当试图理解各种Unicode 规范时)是Unicode Glossary

      【讨论】:

        猜你喜欢
        • 2023-04-02
        • 2017-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-05-08
        • 1970-01-01
        • 2012-05-29
        • 2010-12-13
        相关资源
        最近更新 更多