当前位置: 代码迷 >> 综合 >> JAVA 将中文转为unicode
  详细解决方案

JAVA 将中文转为unicode

热度:81   发布时间:2024-01-21 14:48:57.0
<!--StartFragment -->
public String chinaToUnicode(String str){ 
/*** 中文转 unicode ***/
String result="";
int len=str.length();
for(int i=0;i<len;i++){
            int chr1=(char)str.charAt(i);
            if(chr1>=19968&&chr1<=171941){
                result+=" \\u"+Integer.toHexString(chr1);
            }else{
             result+=str.charAt(i);
            }
        }
return result;
}