2

I'm currently creating something like emoji-keyboard in Android that will show list of emoticon

I don't want to use image, so I need Unicode character for emoji in Java source code to show emoticon in String output.

For example

Unicode Name: FACE WITH TEARS OF JOY
C/C++/Java source code: "\uD83D\uDE02"
http://www.fileformat.info/info/unicode/char/1f602/index.htm

I need Java Unicode like this "\uD83D\uDE02" because when I output Label with

Label.setText("\uD83D\uDE02");`

it works and shows FACE WITH TEARS OF JOY

I've already googled this and found this list, I just don't understand how \uD83D\uDE02 was generated.

Chandra Ari Gunawan
  • 143
  • 1
  • 1
  • 10
  • try this https://github.com/hani-momanii/SuperNova-Emoji – iamkdblue Apr 12 '18 at 03:08
  • Also, see [this question](https://stackoverflow.com/questions/49510006/remove-and-other-such-emojis-images-signs-from-java-string/49574947#49574947) that has some discussion about emoji and Java. – KevinO Apr 12 '18 at 03:09
  • 1
    Welcome to Stack Overflow. When you created your account here, it was suggested you take the [tour] and read the [help] pages in order to familiarize yourself with the site. Please do so, especially [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), before posting your next question here. – Ken White Apr 12 '18 at 03:12
  • yes, i've tried this code, github.com/hani-momanii/SuperNova-Emoji , but it was : Based on Hieu Rocker's library Emojicon Github. and : Emojicon is using emojis graphics from emoji-cheat-sheet.com. it still using an png emoji images.. – Chandra Ari Gunawan Apr 12 '18 at 03:21
  • 1
    U+1f602 is correct Unicode code. The other two are just surrogate representation (I assume UCS2, which do not know about surrogates, because UTF16 should give the correct value) – Giacomo Catenazzi Apr 12 '18 at 09:03

1 Answers1

3

U+1F602 is an unicode codepoint, and Java can read these.

System.out.println(new StringBuilder().appendCodePoint(0x1F602).toString());

If you really need to convert it to the other kind of unicode scapes, you can iterate through all the chars, and write those hex codes to the output:

for(char c : new StringBuilder().appendCodePoint(0x1F602).toString().toCharArray()) {
    System.out.print("\\u" + String.valueOf(Integer.toHexString(c)));
}
System.out.println();
Ferrybig
  • 18,194
  • 6
  • 57
  • 79