java Unicode编码转换为汉字

来源:互联网 发布:网络电视剧上瘾全集 编辑:程序博客网 时间:2024/05/17 02:22
public static String convert(String unicodeStr)    {        if (null == unicodeStr || "".equals(unicodeStr))        {            return unicodeStr;        }        StringBuilder sb = new StringBuilder();        int i = -1;        int pos = 0;                while ((i = unicodeStr.indexOf("\\u", pos)) != -1)        {            sb.append(unicodeStr.substring(pos, i));            if (i + 5 < unicodeStr.length())            {                pos = i + 6;                sb.append((char)Integer.parseInt(unicodeStr.substring(i + 2, i + 6), 16));            }        }        sb.append(unicodeStr.substring(pos, unicodeStr.length()));        return sb.toString();    }

0 0