得到字符串的区位码

/**
  * 得到字符串的区位码
  */
 public static String tran(String str) throws UnsupportedEncodingException {
  byte[] bs = str.getBytes("GB2312");
  String s = "";
  for (int i = 0; i < bs.length; i++) {
   int a = Integer.parseInt(bytes2HexString(bs[i]), 16);
   s += (a - 0x80 - 0x20) + "";
  }
  return s;
 }

 public static String bytes2HexString(byte b) {
  return bytes2HexString(new byte[] { b });
 }

 public static String bytes2HexString(byte[] b) {
  String ret = "";
  for (int i = 0; i < b.length; i++) {
   String hex = Integer.toHexString(b[i] & 0xFF);
   if (hex.length() == 1) {
    hex = '0' + hex;
   }
   ret += hex.toUpperCase();
  }
  return ret;
 }

你可能感兴趣的:(得到字符串的区位码)