Unicode code and Chinese translation

Source: Internet
Author: User

Convert Unicode code to Chinese
public static string TOZHCN (string Unicode) {
StringBuffer GBK = new StringBuffer ();
String hex[] = Unicode.split ("\\\\u");
for (int i = 1; i < hex.length; i++) {//Note to start from 1 instead of 0. The first one is empty.
int data = Integer.parseint (Hex[i], 16); Converts 16 binary numbers to 10-binary data.
Gbk.append ((char) data); Cast to char type is our Chinese character.
}
System.out.println ("This is converted from Unicode to Chinese characters:" + gbk.tostring ());
return gbk.tostring ();
}

public static void Main (string[] args) {
TOZHCN ("\\u8bc1\\u4ef6\\u53f7\\u4e3a\\u7a7a");

}


--------------------------------------------------------------------------------------------------------------- --------------------------


//Convert string to Unicode code
    public static string Tounicode (String zhstr) {
   & nbsp;    StringBuffer Unicode = new StringBuffer ();
        for (int i = 0; i < zhstr.length (); i++) {
             char c = zhstr.charat (i);
            unicode.append ("\\u" + integer.tohexstring (c));
       }
        System.out.println (unicode.tostring ());
        System.out.println (zhstr + "converted to Unicode code succeeded! ");
        return unicode.tostring ();
   }
    
    public static void Main (string[] args) {
         tounicode ("Hello");
    }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Unicode code and Chinese translation

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.