java unicode转码为中文实例
发布时间:2016-12-28 来源:查字典编辑
摘要:复制代码代码如下:packagecom.infomorrow.parser_report;importorg.junit.Test;publ...
复制代码 代码如下:
package com.infomorrow.parser_report;
import org.junit.Test;
public class Decode {
@Test
public void test(){
String uString = "u9053u8def";
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();
}
}