C # code for converting Chinese characters into pinyin abbreviations,

Source: Internet
Author: User

C # code for converting Chinese characters into pinyin abbreviations,

Using System; using System. configuration; using System. data; using System. web; using System. web. security; using System. web. UI; using System. web. UI. htmlControls; using System. web. UI. webControls; using System. web. UI. webControls. webParts; public partial class _ Default: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {Response. write (GetPYString ("People's Republic of China");} public string GetPYString (string str) {string tempStr = ""; foreach (char c in str) {if (int) c> = 33 & (int) c <= 126) {// The original tempStr + = c. toString ();} else {// accumulate pinyin initials tempStr + = GetPYChar (c. toString () ;}} return tempStr ;} ///// obtain the pinyin initials of a single character ///// the single Chinese character to be converted /// the pinyin initials public string GetPYChar (string c) {byte [] array = new byte [2]; array = System. text. encoding. default. getBytes (c); int I = (short) (array [0]-'\ 0') * 256 + (short) (array [1]-'\ 0'); if (I <0xB0A1) return "*"; if (I <0xB0C5) return ""; if (I <0xB2C1) return "B"; if (I <0xB4EE) return "c"; if (I <0xB6EA) return "d"; if (I <0xB7A2) return "e"; if (I <0xB8C1) return "f"; if (I <0xB9FE) return "g"; if (I <0xBBF7) return "h "; if (I <0xBFA6) return "g"; if (I <0xC0AC) return "k"; if (I <0xC2E8) return "l"; if (I <0xC4C3) return "m"; if (I <0xC5B6) return "n"; if (I <0xC5BE) return "o"; if (I <0xC6DA) return "p "; if (I <0xC8BB) return "q"; if (I <0xC8F6) return "r"; if (I <0 xCBFA) return "s "; if (I <0 xCDDA) return "t"; if (I <0xCEF4) return "w"; if (I <0xD1B9) return "x"; if (I <0xD4D1) return "y"; if (I <0xD7FA) return "z"; return "*";}}

C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

Symbol in C Language <Yes

Left shift operator (<)

Removes all the binary bits of an operation object from the left and adds 0 to the right ).

For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,

Move 1 to the left and then a = a * 2;

If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)

Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.

The operand shifts one digit to the right, which is equivalent to dividing the number by 2.

For example, a = a> 2 shifts the binary bit of a two places to the right,

0 or 1 to see whether the number is positive or negative.

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.