java - 如何在 Java 中编写 3 个字节的 unicode 文字?

标签 java unicode utf-16 utf-32 unicode-literals

我想用 Java 编写 unicode 文字 U+10428。 http://www.marathon-studios.com/unicode/U10428/Deseret_Small_Letter_Long_I

我尝试使用“\u10428”,但无法编译。

最佳答案

由于 Java 在人们认为 64K 对每个人都足够时(以前从哪里听说过这样的消息?)开始使用 UCS-2,后来升级到 UTF-16。

但他们从来没有为 BMP 之外的 unicode 字符添加转义序列。

因此,您唯一的办法是手动重新编码为 UTF-16 代理项对并使用两次 UTF-16 转义。

您的示例代码点 U+10428"\uD801\uDC28"

我使用这个网站进行重新编码:https://rishida.net/tools/conversion/

Quote from the docs :

3.10.5 String Literals

A string literal consists of zero or more characters enclosed in double quotes. Characters may be represented by escape sequences (§3.10.6) - one escape sequence for characters in the range U+0000 to U+FFFF, two escape sequences for the UTF-16 surrogate code units of characters in the range U+010000 to U+10FFFF.

关于java - 如何在 Java 中编写 3 个字节的 unicode 文字?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24633273/

相关文章:

Java:获取 List<List<String>> 的所有串联

java - 如果 Kafka 和 Zookeeper 未运行,为什么 Maven Clean Install 无法完成?

c# - 反射是否打破了私有(private)方法的想法,因为私有(private)方法可以在类之外访问?

java - 如何阻止已经登录的用户从其他浏览器登录

python - 使用 lxml.html 的 cssselect 选择 ID 属性中带有冒号的元素

utf-8 - Emacs 中的 Rgrep 使用 ripgrep

python - Python 中的 unicode 类

python - 如何将 Unicode 字符串转换为 TCHAR 系统?

asp.net-mvc - 当指定 UTF-8 时,为什么 ASP.NET MVC 中的 ContentResult Controller 返回 UTF-16?

c# - 有什么理由比 UTF-8 更喜欢 UTF-16?