I want java escape code for all emojis. For e.g if anyone put up smiley then I want its java code which is "\ud83d\ude05" . Anybody knows how to convert emojis to its java code as I said in above e.g ?
Asked
Active
Viewed 834 times
2 Answers
1
It's not too hard to write one:
import java.util.stream.Collectors;
class StringRepr {
private static String escapeChar(int c) {
if (c <= 0x7f) {
return Character.toString((char) c);
} else {
return "\\u" + String.format("%04x", c);
}
}
public static String escape(String s) {
return s.chars().mapToObj(c -> escapeChar(c)).collect(Collectors.joining());
}
public static void main (String[] args) {
System.out.println(escape(""));
}
}

Amadan
- 191,408
- 23
- 240
- 301
0
"\\ud83d\\ude05" You can try this ,"\"this element hava a special sense
-
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). – Narendra Jadhav Sep 07 '18 at 07:27