如何通过Javascript将六位表情符号代码转码为Unicode? (`328054` 到 `\ue052`)

How to transcode six digits emoji code to Unicode by Javascript? (`328054` to `\ue052`)

有些文本包含六位数字的表情符号。我需要通过 JavaScript 将它转码为 Unicode。

就像这样:

origin:  328054 


Unicode:  \ue052    ( U+E052  'the dog face' Emoji )

如何通过 Javascript 将这六位表情符号代码转码为 Unicode?

origin: 328054

我不明白你的意思。如果处理为十进制,U+50176 不是有效的 Unicode 字符。如果处理为十六进制,则它位于 Unicode 可以表示的代码点范围之外。

Unicode: \ue052 ( U+E052 )

U+E052 is reserved for private use. You don't mean that one. It seems to have been used by SoftBank狗脸 表情符号进行编码。除非你住在日本,并使用他们的网络,否则它几乎不适合你。

'the dog face' Emoji

已分配 U+1F436: </code>.</p> <blockquote> <p>How can I encode this in Javascript?</p> </blockquote> <p>JavaScript 使用 <a href="https://en.wikipedia.org/wiki/UTF-16" rel="noreferrer">UTF-16</a>, and since your code point is higher than U+D7FF, you will need two characters to encode it as a surrogate pair. You still can easily get the string from the code point by using <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCodePoint" rel="noreferrer"><code>String.fromCodePoint:

var df = String.fromCodePoint(0x1F436);
df.length; // 2

您可以使用 charCodeAt method:

获取从该字符串转义所需的字符代码
String.fromCodePoint(0x1F436).charCodeAt(0).toString(16) // d83d
String.fromCodePoint(0x1F436).charCodeAt(1).toString(16) // dc36

所以你似乎想要的 JS 字符串文字是 "\ud83d\udc36".