Skip to content

Instantly share code, notes, and snippets.

@sbcoba
Created June 18, 2016 07:55
Show Gist options
  • Save sbcoba/0c058658565c0f180fb6a06b9170f939 to your computer and use it in GitHub Desktop.
Save sbcoba/0c058658565c0f180fb6a06b9170f939 to your computer and use it in GitHub Desktop.
Java String Unicode converter
public static String unicodeConvert(String str) {
StringBuilder sb = new StringBuilder();
char ch;
int len = str.length();
for (int i = 0; i < len; i++) {
ch = str.charAt(i);
if (ch == '\\' && str.charAt(i + 1) == 'u') {
sb.append((char) Integer.parseInt(str.substring(i + 2, i + 6), 16));
i += 5;
continue;
}
sb.append(ch);
}
return sb.toString();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment