Use the shift method to obtain Chinese character encoding

Source: Internet
Author: User

The Chinese character encoding is also represented by a number like an English character, but we can directly insert an ASCII table into the corresponding English character. How do we know the encoding of a Chinese character ???

Simply put, the Chinese character storage occupies two bytes, and the first byte corresponds to the number shifted to eight places, plus the number corresponding to the second byte, is the final Chinese character encoding. Use C # To make the interface as follows:

CorrespondingCodeThe principle is as follows: read any book. The results are displayed in textbox and ListBox.

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. LINQ; using system. text; using system. threading. tasks; using system. windows. forms; namespace get Chinese character code {public partial class form1: FORM {public form1 () {initializecomponent ();} private void btnsure_click (Object sender, eventargs e) {int K = 0; txtoutput. TEXT = ""; int I = txtinput. text. length; while (k <I) {char c = txtinput. text [k]; byte [] gb2312_bt = encoding. getencoding ("gb2312 "). getbytes (New char [] {c}); int n = (INT) gb2312_bt [0] <8; n + = (INT) gb2312_bt [1]; txtoutput. TEXT = n. tostring () + "\ r \ n" + txtoutput. text; listbox1.items. add (txtinput. text [k] + ":" + N. tostring (); ++ K;} private void txtoutput_textchanged (Object sender, eventargs e ){}}}

The effect is as follows:

 

 

 

 

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.