How to generate emoji unicode like "\uD83D\uDE02" when i got is "U+1F602"?

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"

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.

5

1 Answer

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();

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like