java unicode转码为中文实例
程序员文章站
2023-12-21 13:23:16
复制代码 代码如下:package com.infomorrow.parser_report;
import org.junit.test;
public class...
复制代码 代码如下:
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();
}
}