Reputation: 13827
I want to know how to convert "\u106A" to "A" or something else? I've found following coding to convert Hex to character but it failed
public static String convertHexToString(String hex){
StringBuilder sb = new StringBuilder();
StringBuilder temp = new StringBuilder();
for( int i=0; i<hex.length()-1; i+=2 ){
String output = hex.substring(i, (i + 2));
int decimal = Integer.parseInt(output, 16);
sb.append((char)decimal);
temp.append(decimal);
}
return sb.toString();
}
Upvotes: 0
Views: 1451
Reputation: 30874
You can use StringEscapeUtils.unescapeJava
available in Commons Lang
Apache library.
final String input = "\\u0048\\u0065\\u006c\\u006c\\u006f\\u002c\\u0020\\u0057\\u006f\\u0072\\u006c\\u0064\\u0021";
final String output = StringEscapeUtils.unescapeJava(input);
System.out.println("Output : " + output);
// Output : Hello, World!
Upvotes: 1