简体   繁体   中英

How to convert a bytes string to unicode value to display emoji in Java?

I used the pepibumur/emojize in web project, not Android or iOS.

The project defined the relationship with unicode and word, so I must find the emoji string and convert to unicode.

the emoji unicode table like that http://apps.timwhitlock.info/emoji/tables/unicode .

I already get the byte string like that \\xf0\\x9f\\x9a\\x92 .

But I didn't know how to convert to the unicode U+1F692 , How to convert? Thank you!

To convert from UTF-8 bytes you need:

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

But it's too complex, and I recommend to use value from Surrogates column:

String s = "\uD83D\uDE4C";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM