1

如何转换此字符串:此字符串包含 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;
}    
4

1 回答 1

1

要将 unicode 转换为字符串,请使用

StringEscapeUtils .unescapeJava(unicodeString)

于 2013-07-17T07:00:40.630 回答