Conversion of Chinese characters to unicode, conversion of Chinese characters to hexadecimal, and conversion of unicode
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 }
Help: unicode and Chinese character conversion program, which requires hexadecimal unicode and Chinese character conversion
Conversion Program, search for CodeConvert
The vb function Code is as follows:
Add to your program to make the following method call:
Hexadecimal conversion text (source code variable, separator [optional, default space])
Public Function hexadecimal conversion text (ByVal code As String, Optional ByVal separator As String = "") As String
Dim LA As Integer = Len (CODE), LB As Integer = Len (separator)
If LA <2 Then Return Nothing
Dim Bin (LA + LB)/3-1) As Byte, I As Integer = 0
For I = 0 To Bin. Length-1
Buffer. SetByte (Bin, I, Val ("& H" & Mid (code, I * (LB + 2) + 1, 2 )))
Next
Return Encoding. Default. GetString (Bin)
End Function
How to convert Chinese characters to Unicode encoded hexadecimal
First, find out the current Chinese character encoding method, such as win32's default GBK, and then find the gbk to unicode encoding conversion table. You can find it in the array during conversion.
There should be a conversion table on the Internet. It's inconvenient for me to transfer it out.