Use Java to convert Chinese characters to Unicode

Source: Internet
Author: User

I thought. tounicode would work.

Result .........

On the front-end pageCodeType: gb2312
In the action page, the gb2312 code becomes garbled.
So we need to convert gb2312 code to ISO-8859-1
// Transcoding from "gb2312" to "ISO-8859-1"
Public String iso2gb (string Str ){
Try {
STR = new string (Str. getbytes ("ISO-8859-1"), "gb2312 ");
} Catch (exception e ){
System. Out. println ("Encoding Error! ");
}
Return STR;
}
Then convert the ISO-8859-1 to Unicode

Char [] archar = iso2gb (SEA). tochararray ();
Int ivalue = 0;
String USTR = "";
For (INT I = 0; I <archar. length; I ++ ){
Ivalue = (INT) iso2gb (SEA). charat (I );
If (ivalue <= 256 ){
// USTR + = "" + integer. tohexstring (ivalue) + ";";
USTR + = "\ u00" + integer. tohexstring (ivalue );
} Else {
// USTR + = "" + integer. tohexstring (ivalue) + ";";
USTR + = "\ U" + integer. tohexstring (ivalue );
}
}

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.