在Java中将Unicode转换为字符串,将String转换为Unicode

时间:2012-09-12 08:56:34

标签: java string unicode

如何转换此字符串: 这个字符串包含unicode字符unicodetoString(“\ u0064”)和字符串到unicode,如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;
}    

1 个答案:

答案 0 :(得分:1)

将unicode转换为字符串使用

StringEscapeUtils。unescapeJava(的UnicodeString)