Java语言对unicode转中文(unicode码之间混杂有数字和英文)

Java语言对unicode转中文(unicode码之间混杂有数字和英文)
啥都不说了,直接上代码
public static String decodeUnicode(String unicode) {
        List<String> list = new ArrayList<String>();
        String reg= "\\\\u[0-9,a-f,A-F]{4}";
        Pattern p = Pattern.compile(reg);
        Matcher m=p.matcher(unicode);
        while (m.find()){
            list.add(m.group());
        }
        for (int i = 0, j = 2; i < list.size(); i++) {
            String code = list.get(i).substring(j, j + 4);
            char ch = (char) Integer.parseInt(code, 16);
            unicode = unicode.replace(list.get(i),String.valueOf(ch));
        }
        return unicode;
    }
    public static void main(String[] args) throws Exception {
        String str = "2002\\u5e7412\\u67081\\u65e5\\u96f6love\\u65f6\\uff0c\\u5f53\\u6b27\\u76df\\u5728\\u5e03\\u9c81\\u585e\\u5c14\\u738b";
        System.out.println(decodeUnicode(str));
    }

效果:

2002年12月1日零love时,当欧盟在布鲁塞尔王
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值