Conversion of Chinese characters to unicode, conversion of Chinese characters to hexadecimal, and conversion of unicode

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.