其他分享
首页 > 其他分享> > unicode转中文

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/

标签:中文,ch,group,unicode,matcher,group1,str,String
来源: https://www.cnblogs.com/gczmn/p/10576275.html