Reputation: 127
How can I convert this string: This string contains the unicode character unicodetoString("\u0064") and string to unicode like stringtounicode("a")?
public static String GetUnicode(String str_code) {
String hexCode = Integer.toHexString(str_code.codePointAt(0)).toUpperCase();
String hexCodeWithAllLeadingZeros = "0000" + hexCode;
String hexCodeWithLeadingZeros = hexCodeWithAllLeadingZeros
.substring(hexCodeWithAllLeadingZeros.length() - 4);
hexCodeWithLeadingZeros = "\\u" + hexCodeWithLeadingZeros;
System.out.println("Unicode " + hexCodeWithLeadingZeros);
return hexCodeWithLeadingZeros;
}
Upvotes: 2
Views: 9692
Reputation: 3679
To Convert a unicode to string use
StringEscapeUtils.unescapeJava(unicodeString)
Upvotes: 1