public static String unicodeToString(String str) {
 
    Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");    
    Matcher matcher = pattern.matcher(str);
    char ch;
    while (matcher.find()) {
        ch = (char) Integer.parseInt(matcher.group(2), 16);
        str = str.replace(matcher.group(1), ch + "");    
    }
    return str;
}

获取字符串的unicode编码,这个我们可以通过直接获取字符串的unicode二进制,然后将其byte转换成对应的16进制表示

static String getUnicode(String s) {
        try {
            StringBuffer out = new StringBuffer("");
            byte[] bytes = s.getBytes("unicode");
            for (int i = 0; i < bytes.length - 1; i += 2) {
                out.append("\\u");
                String str = Integer.toHexString(bytes[i + 1] & 0xff);
                for (int j = str.length(); j < 2; j++) {
                    out.append("0");
                }
                String str1 = Integer.toHexString(bytes[i] & 0xff);
                out.append(str1);
                out.append(str);
                 
            }
            return out.toString();
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
            return null;
        }
    }

http://www.cnblogs.com/xignzou/p/3329438.html

相关文章:

  • 2022-01-07
  • 2021-12-29
  • 2022-12-23
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-30
  • 2021-09-30
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案