当前位置: 移动技术网 > IT编程>开发语言>Java > java unicode转码为中文实例

java unicode转码为中文实例

2019年07月22日  | 移动技术网IT编程  | 我要评论

复制代码 代码如下:

package com.infomorrow.parser_report;

import org.junit.test;

public class decode {
    @test
    public void test(){
        string ustring = "\\u9053\\u8def";
        system.out.println(ascii2native(ustring));//道路
    }

    public static string ascii2native(string ascii) { 
        int n = ascii.length() / 6; 
        stringbuilder sb = new stringbuilder(n); 
        for (int i = 0, j = 2; i < n; i++, j += 6) { 
            string code = ascii.substring(j, j + 4); 
            char ch = (char) integer.parseint(code, 16); 
            sb.append(ch); 
        } 
        return sb.tostring(); 
    } 
}

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网