unicode转中文

/**
     * Unicode转 汉字字符串
     *
     * @param str \u6728
     * @return '木' 26408
     */
public static String unicodeToString(String str) {
 
    Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");
    Matcher matcher = pattern.matcher(str);
    char ch;
    while (matcher.find()) {
        //group 6728
        String group = matcher.group(2);
        //ch:'木' 26408
        ch = (char) Integer.parseInt(group, 16);
        //group1 \u6728
        String group1 = matcher.group(1);
        str = str.replace(group1, ch + "");
    }
    return str;
}

更多参考: https://blog.csdn.net/u013905744/article/details/74452012/

posted @ 2019-03-22 09:31  弓长张&木子李  阅读(394)  评论(0编辑  收藏  举报