首页 > 其他 > 详细

unicode转中文

时间:2019-03-22 10:32:42      阅读:122      评论:0      收藏:0      [点我收藏+]
/**
     * 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/

unicode转中文

原文:https://www.cnblogs.com/gczmn/p/10576275.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!