Created
June 18, 2016 07:55
-
-
Save sbcoba/0c058658565c0f180fb6a06b9170f939 to your computer and use it in GitHub Desktop.
Java String Unicode converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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