gpt4 book ai didi

ios - 谁能告诉我如何在 Objective-c 中将 UTF-8 值转换为 UCS-2 值?

转载 作者:搜寻专家 更新时间:2023-10-30 20:22:26 27 4
gpt4 key购买 nike

我正在尝试将 UTF-8 字符串转换为 UCS-2 字符串。我需要得到像“\uFF0D\uFF0D\u6211\u7684\u4E0A\u7F51\u4E3B\u9875”这样的字符串。到目前为止,我已经搜索了大约一个月,但仍然没有关于将 UTF-8 转换为 UCS-2 的引用资料。请有人帮助我。提前致谢。

编辑:好吧,也许我的解释不够好。这就是我想要做的。我住在韩国,我正在尝试使用 CTMessageCenter 发送短信。我试图通过我的应用程序发送简体中文字符。我得到了????而不是适当的字符。所以我也尝试了 UTF-8、UTF-16、BE 和 LE。但他们都回来了??。最后我发现 SMS 在韩国使用 UCS-2 和 EUC-KR 编码。很奇怪,不是吗?无论如何,我尝试发送像\u4E3B\u9875 这样的字符串并且它起作用了。所以我需要先将字符串转换为 UCS-2 编码,然后从这些字符串中获取字符串文字。

最佳答案

Wikipedia :

The older UCS-2 (2-byte Universal Character Set) is a similar character encoding that was superseded by UTF-16 in version 2.0 of the Unicode standard in July 1996.2 It produces a fixed-length format by simply using the code point as the 16-bit code unit and produces exactly the same result as UTF-16 for 96.9% of all the code points in the range 0-0xFFFF, including all characters that had been assigned a value at that time.

IBM :

Since the UCS-2 standard is limited to 65,535 characters, and the data processing industry needs over 94,000 characters, the UCS-2 standard is in the process of being superseded by the Unicode UTF-16 standard.

However, because UTF-16 is a superset of the existing UCS-2 standard, you can develop your applications using the systems existing UCS-2 support as long as your applications treat the UCS-2 as if it were UTF-16.

uincode.org :

UCS-2 is obsolete terminology which refers to a Unicode implementation up to Unicode 1.1, before surrogate code points and UTF-16 were added to Version 2.0 of the standard. This term should now be avoided.

UCS-2 does not define a distinct data format, because UTF-16 and UCS-2 are identical for purposes of data exchange. Both are 16-bit, and have exactly the same code unit representation.

因此,在大多数语言库中使用“UTF8toUnicode”转换将生成 UTF-16,本质上是 UCS-2。只需从 Objective-C 字符串中提取 16 位字符即可完成同样的事情。

换句话说,解决方案一直在盯着你看。

关于ios - 谁能告诉我如何在 Objective-c 中将 UTF-8 值转换为 UCS-2 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6967251/

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