【问题标题】:How to convert a bytes string to unicode value to display emoji in Java?如何将字节字符串转换为 unicode 值以在 Java 中显示表情符号?
【发布时间】:2015-04-02 08:42:24
【问题描述】:

我在 web 项目中使用了pepibumur/emojize,而不是 Android 或 iOS。

项目定义了unicode和word的关系,所以我必须找到emoji字符串并转换成unicode。

http://apps.timwhitlock.info/emoji/tables/unicode这样的表情符号unicode表。

我已经得到了像\xf0\x9f\x9a\x92 这样的字节串。

但我不知道如何转换为 unicode U+1F692,如何转换?谢谢!

【问题讨论】:

    标签: java unicode emoji


    【解决方案1】:

    要从 UTF-8 字节转换,您需要:

    String s = new String(new byte[]{(byte) 0xF0, (byte) 0x9F, (byte) 0x98, (byte) 0x81}, "UTF-8");
    

    但它太复杂了,我建议使用来自Surrogates列的值:

    String s = "\uD83D\uDE4C";
    

    【讨论】:

      猜你喜欢
      • 2019-05-20
      • 1970-01-01
      • 2020-06-23
      • 1970-01-01
      • 1970-01-01
      • 2020-08-20
      • 2016-02-21
      • 2016-03-22
      • 2016-10-22
      相关资源
      最近更新 更多