How to convert UTF16 (emoji) to HTML Entity (hex) using java

后端 未结 2 960
终归单人心
终归单人心 2021-02-11 06:27
How to convert UTF16 (emoji) to HTML Entity (hex) using java


I have the string from DB like this \"\\uD83D\\uDE02\". 
I try to display this unicode emoji, it displays          


        
相关标签:
2条回答
  • 2021-02-11 07:21

    Although the string appears to contain two Unicode characters, it's already one character encoded in UTF-16, that's how Java strings work. You can determine the actual UTF-16-decoded character code using the String.codePointAt method. Here the character's code is 0x1F602, which is Unicode 'FACE WITH TEARS OF JOY':

    0 讨论(0)
  • 2021-02-11 07:28

    You can use emoji4j library for this.

    For example:

    String line = "Hi , i am fine \uD83D\uDE02 \uD83D\uDE02, how r u ?";
    
    EmojiUtils.hexHtmlify(line); //Hi , i am fine 😂 😂, how r u ?
    
    0 讨论(0)
提交回复
热议问题