java unicode轉碼為中文實例。本站提示廣大學習愛好者:(java unicode轉碼為中文實例)文章只能為提供參考,不一定能成為您想要的結果。以下是java unicode轉碼為中文實例正文
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();
}
}