簡體   English   中英

在Java中將Unicode轉換為字符串並將String轉換為Unicode

[英]Converting Unicode to string and String to Unicode in Java

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

要將Unicode轉換為字符串,請使用

StringEscapeUtils .unescapeJava(unicodeString)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM