Get emoticon unicode from char UTF-16

我的未来我决定 提交于 2019-12-06 05:27:55

I get an UTF-16 char (0xD83D 0xDE04), Is it possible to convert this char value to the unicode value?

For just a single code point in a string, you can convert it to an integer with:

int codepoint = "\uD83D\uDE04".codePointAt(0);  // 0x1F604

It is, however quite tedious to go over a whole string with codePointCount/codePointAt. Java/Dalvik's String type is strongly tied to UTF-16 code units and the codePoint methods are a poorly-integrated afterthought. If you are simply hoping to replace an emoji with some other string of characters, you are probably best off doing a plain string replace or regex with the two code units as they appear in the String type, eg text.replace("\uD83D\uDE04", ":-D").

(BTW Face with medical mask is U+1F637.)

\u1f604 is the UTF-32 encoding of that emoticon. You can convert this way:

byte[] bytes = "\uD83D\uDE37".getBytes("UTF-32BE");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!