首页 > 代码库 > 汉字转unicode , 汉字转16进制

汉字转unicode , 汉字转16进制

 1 public static String toUnicode(String s) 2     { 3         String as[] = new String[s.length()]; 4         String s1 = ""; 5         for (int i = 0; i < s.length(); i++) 6         { 7             as[i] = Integer.toHexString(s.charAt(i) & 0xffff); 8             s1 = s1 + as[i]+"\t"; 9         }10         return s1;11     }

 

 1 public static String toChineseHex(String s) 2     { 3         String ss = s; 4         byte[] bt = ss.getBytes(); 5         String s1 = ""; 6         for (int i = 0; i < bt.length; i++) 7         { 8             String tempStr = Integer.toHexString(bt[i]); 9             if (tempStr.length() > 2)10                 tempStr = tempStr.substring(tempStr.length() - 2);11             s1 = s1 + tempStr + " ";12         }13         return s1.toUpperCase();14     }

 

汉字转unicode , 汉字转16进制