1 main方法
String a = "全部产区";
String aa = chinaToUnicode(a);System.out.println("测试:"+aa);
2 调用转化方法
private static String chinaToUnicode(String str){
String result="";
for (int i = 0; i < str.length(); i++){
int chr1 = (char) str.charAt(i);
if(chr1>=19968&&chr1<=171941){//汉字范围 \u4e00-\u9fa5 (中文)
result+="\\u" + Integer.toHexString(chr1);
}else{
result+=str.charAt(i);
}
}
return result;
}