我想在我的 iOS 和 Android 应用程序中使用表情符号。我在这里检查了表情符号列表,它列出了表情符号的十六进制代码。当我尝试直接使用十六进制代码时U+1F600,我在应用程序中看不到表情符号。我发现了另一种表示表情符号的方式,看起来像\uD83D\uDE00. 使用此表示法时,无需任何额外代码即可在应用程序中看到表情符号。我认为这是表情符号的 Unicode 字符串。我认为这更像是一个针对表情符号的普遍问题。如何将表情符号十六进制代码转换为如上所示的 Unicode 字符串。我没有找到任何列出表情符号 Unicode 的列表。
看来你的问题实际上是“如何显示一个字符,知道它的代码点?”
This question turns out to be rather language-dependent! Modern languages have little trouble with this. In Swift, we do this:
$ swift
Welcome to Apple Swift version 3.0.2 (swiftlang-800.0.63 clang-800.0.42.1). Type :help for assistance.
1> "\u{1f600}"
$R0: String = ""
Run Code Online (Sandbox Code Playgroud)
In JavaScript, it is the same:
$ node
> "\u{1f600}"
''
Run Code Online (Sandbox Code Playgroud)
In Java, you have to do a little more work. If you want to use the code point directly you can say:
new StringBuilder().appendCodePoint(0x1f600).toString();
Run Code Online (Sandbox Code Playgroud)
The sequence "\uD83D\uDE00" also works in all three languages. This is because those "characters" are actually what Unicode calls surrogates and when they are combined together a certain way they stand for a single character. The details of how this all works can be found on the web in many places (look for UTF-16 encoding). The algorithm is there. In a nutshell you take the code point, subtract 10000 hex, and spread out the 20 bits of that difference like this: 110110xxxxxxxxxx110111xxxxxxxxxx.
But rather than worrying about this translation, you should use the code point directly if your language supports it well. You might also be able to copy-paste the emoji character into a good text editor (make sure the encoding is set to UTF-8). If you need to use the surrogates, your best best is to look up a Unicode chart that shows you something called the "UTF-16 encoding."
| 归档时间: |
|
| 查看次数: |
8721 次 |
| 最近记录: |