gpt4 book ai didi

visual-c++ - 对 Unicode 和多字节文章的困惑

转载 作者:行者123 更新时间:2023-12-04 03:35:03 26 4
gpt4 key购买 nike

通过引用 Joel's Article

Some people are under the misconception that Unicode is simply a 16-bit code where each character takes 16 bits and therefore there are 65,536 possible characters. This is not, actually, correct.



看完整篇文章,我的观点是,如果有人告诉你,他的文本是 unicode 的,你将不知道他的每个角色占用了多少内存空间。他必须告诉你,“我的 unicode 文本是用 UTF-8 编码的”,那么只有你知道他的每个角色占用了多少内存空间。

Unicode = 每个字符不需要 2 个字节

然而,当谈到 Code Project's ArticleMicrosoft's Help ,这让我很困惑:

微软:

Unicode is a 16-bit character encoding, providing enough encodings for all languages. All ASCII characters are included in Unicode as "widened" characters.



代码项目:

The Unicode character set is a "wide character" (2 bytes per character) set that contains every character available in every language, including all technical symbols and special publishing characters. Multibyte character set (MBCS) uses either 1 or 2 bytes per character



Unicode = 每个字符 2 个字节?

65536 个可能的字符能代表这个世界上所有的语言吗?

为什么 Web 开发者社区和桌面开发者社区的概念似乎不同?

最佳答案

曾几何时,

  • Unicode 在 16 位中只有尽可能多的字符,而
  • UTF-8 不存在或者不是要使用的事实上的编码。

  • 这些因素导致 UTF-16(或者更确切地说,现在称为 UCS-2)被认为是“Unicode”的同义词,因为它毕竟是支持所有 Unicode 的编码。

    实际上,您会看到在表示“UTF-16”或“UCS-2”的地方使用了“Unicode”。这是一个历史性的困惑,应该被忽视而不是传播。 Unicode 是一组字符; UTF-8、UTF-16 和 UCS-2 是不同的编码。

    (UTF-16 和 UCS-2 之间的区别在于 UCS-2 是真正的 16 位每“字符”编码,因此仅编码 Unicode 的“BMP”(基本多语言平面)部分,而 UTF- 16 使用“代理对”(总共 32 位)来编码高于 BMP 的字符。)

    关于visual-c++ - 对 Unicode 和多字节文章的困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2384160/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com