Unicode转字符串

    private String unicodeToString(String string) {
        StringBuffer stringBuffer = new StringBuffer() ;
        String pattern = "\\\\u[0-9,a-f,A-F]{4}";
        Matcher matcher = Pattern.compile(pattern).matcher(string);
        while (matcher.find()) {
            char c = (char) Integer.parseInt(matcher.group().replaceAll("\\\\u", ""), 16);
            matcher.appendReplacement(stringBuffer, new String(new char[]{c}));
        }
        matcher.appendTail(stringBuffer);
        return stringBuffer.toString();
    }

 

posted @ 2019-02-21 12:08  柚子苹果果  阅读(596)  评论(0编辑  收藏  举报