fork(2) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String str = "é😅";
  13. StringBuilder sb = new StringBuilder(str.length());
  14. for (int i = 0; i < str.length(); ++i) {
  15. char c = str.charAt(i);
  16. if (Character.isHighSurrogate(c) || Character.isLowSurrogate(c)) {
  17. // Append the escaped character.
  18. sb.append("\\u");
  19. sb.append(String.format("%04x", (int) c));
  20. } else {
  21. // Append the character as-is.
  22. sb.append(c);
  23. }
  24. }
  25. String partlyEscaped = sb.toString();
  26. System.out.println(partlyEscaped);
  27. }
  28. }
Success #stdin #stdout 0.04s 711168KB
stdin
Standard input is empty
stdout
é\ud83d\ude05