Number of bytes of English letters and Chinese characters encoded in different character sets

Source: Internet
Author: User

English letters:

Number of bytes: 1; encoding: gb2312

Number of bytes: 1; encoding: GBK

Number of bytes: 1; encoding: gb18030

Byte Count: 1; encoding: ISO-8859-1

Byte Count: 1; encoding: UTF-8

Byte Count: 4; encoding: UTF-16

Byte Count: 2; encoding: UTF-16BE

Byte Count: 2; encoding: UTF-16LE

 

Chinese characters:

Number of bytes: 2; encoding: gb2312

Number of bytes: 2; encoding: GBK

Number of bytes: 2; encoding: gb18030

Byte Count: 1; encoding: ISO-8859-1

3; encoding: UTF-8

Byte Count: 4; encoding: UTF-16

Byte Count: 2; encoding: UTF-16BE

Byte Count: 2; encoding: UTF-16LE

You can useCodeSee the above results:

Import java. Io. unsupportedencodingexception;

 

Public class encodingtest {

 

/**

* @ Param ARGs

*/

Public static void main (string [] ARGs ){

String en = "";

String CH = "persons ";

System. Out. println ("English letter:" + en );

Printbytelength (EN, "gb2312 ");

Printbytelength (EN, "GBK ");

Printbytelength (EN, "gb18030 ");

Printbytelength (EN, "ISO-8859-1 ");

Printbytelength (EN, "UTF-8 ");

Printbytelength (EN, "UTF-16 ");

Printbytelength (EN, "UTF-16BE ");

Printbytelength (EN, "UTF-16LE ");

System. Out. println ();

 

System. Out. println ("Chinese characters:" + CH );

Printbytelength (CH, "gb2312 ");

Printbytelength (CH, "GBK ");

Printbytelength (CH, "gb18030 ");

Printbytelength (CH, "ISO-8859-1 ");

Printbytelength (CH, "UTF-8 ");

Printbytelength (CH, "UTF-16 ");

Printbytelength (CH, "UTF-16BE ");

Printbytelength (CH, "UTF-16LE ");

}

 

/**

* Print the number of bytes occupied by Java strings in different character sets

*

* @ Param Str

* String to be operated

* @ Param encodingname

* Character Set Name

**/

Public static void printbytelength (string STR, string encodingname ){

System. Out. Print ("Bytes :");

Try {

System. Out. Print (Str. getbytes (encodingname). Length );

} Catch (unsupportedencodingexception e ){

E. printstacktrace ();

}

System. Out. println ("; encoding:" + encodingname );

}

}

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.