中文转unicode

中文转unicode 字符方法
public  String gbEncoding( String gbString) {   //gbString = "测试"
   char[] utfBytes = gbString.toCharArray();   //utfBytes = [测, 试]
   String unicodeBytes = "";
   for (int byteIndex = 0; byteIndex < utfBytes.length; byteIndex++) {
      String hexB = Integer.toHexString(utfBytes[byteIndex]);   //转换为16进制整型字符串
      if (hexB.length() <= 2) {
         hexB = "00" + hexB;
      }
      unicodeBytes = unicodeBytes + "\\u" + hexB;
   }
   return unicodeBytes;
}

你可能感兴趣的:(笔记)