小编Inf*_*and的帖子

在 Java 中显示 UTF-8 表情符号

假设我有(魔鬼)表情符号。

在 4 字节 UTF-8 中,它的表示方式如下:\u00f0\u009f\u0098\u0088

然而,在 Java 中,它只能正确打印,如下所示:\ud83d\ude08

我如何从第一个转换为第二个?

更新2

MNEMO 的答案要简单得多,并且回答了我的问题,因此最好采用他的解决方案。

更新

感谢巴兹尔·布尔克的撰写。它很有意思。

我在这里找到了一个很好的参考:https://github.com/pRizz/Unicode-Converter/blob/master/conversionfunctions.js(特别是convertUTF82Char()函数)。

对于将来路过这里的任何人来说,Java 中的情况如下:

public static String fromCharCode(int n) {
    char c = (char)n;
    return Character.toString(c);
}

public static String decToChar(int n) {
    // converts a single string representing a decimal number to a character
    // note that no checking is performed to ensure that this is just a hex number, eg. no spaces etc
    // dec: string, the dec codepoint to …
Run Code Online (Sandbox Code Playgroud)

java byte utf-8 utf-16 emoji

2
推荐指数
1
解决办法
7914
查看次数

标签 统计

byte ×1

emoji ×1

java ×1

utf-16 ×1

utf-8 ×1