Gets the initials of the first pinyin of the Chinese character string

Source: Internet
Author: User
Tags range tostring
Chinese characters | pinyin | String headers may be less clear and implement the following features: I love China-WAZG
1. The difference between Chinese characters and English letters
The standard ASC table does not contain kanji characters, because a ASC character is only 1byte, which is the range of digits that 8bit,8bit can represent, if it is a good sign, because it is-128-127, unsigned, it should be 0-255. And we know that a Chinese character, should occupy 2 byte, the range should be-32768-32767, so the ASC for Chinese characters, for example a bit:11002111,11111101 it represents a character that should exceed the range that ASC can express, This is where the overflow occurs. Therefore, the ASC code, which occupies two-byte kanji characters, should be negative.
2. Function realization
1using System;
2using System.Collections.Generic;
3using System.Text;
4
5namespace ConsoleApplication1
6{
7 Class Program
8 {
9 static void Main (string[] args)
10 {
One Console.WriteLine (Getchinesefirstchar ("I a*% Love You China"))
12}
static string Getchinesefirstchar (String chinesestr)
14 {
StringBuilder sb = new StringBuilder ();
int length = Chinesestr.length;
for (int i = 0; i < length; i++)
18 {
Char Chinesechar = chinesestr[i];
SB. Append (Getpychar (Chinesechar));
21}
Return SB. ToString ();
23}
static string Getpychar (char c)
25 {
num int asccode = MICROSOFT.VISUALBASIC.STRINGS.ASC (c);
int temp = 65536 + Asccode;
if (temp >= 45217 && temp <= 45252)
29 {
return "A";
31}
else if (temp >= 45253 && temp <= 45760)
33 {
return "B";
35}
"Else If" (temp >= 45761 && temp <= 46317)
37 {
return "C";
39}
else if (temp >= 46318 && temp <= 46825)
41 {
return "D";
43}
44
45
' Else if ' (temp >= 46826 && temp <= 47009)
47 {
"E";
49}
or else if (temp >= 47010 && temp <= 47296)
51 {
The return "F";
53}
"Else If" (temp >= 47297 && temp <= 47613)
55 {
return "G";
57}
/else if (temp >= 47614 && temp <= 48118)
59 {
return "H";
61}
' Else if ' (temp >= 48119 && temp <= 49061)
63 {
return "J";
65}
"Else If" (temp >= 49062 && temp <= 49323)
67 {
The return "K";
69}
>= else if (temp 49324 && temp <= 49895)
71 {
The return of "L";
73}
>= else if (temp 49896 && temp <= 50370)
75 {
The return of "M";
77}
' Else if ' (temp >= 50371 && temp <= 50613)
79 {
"N";
81}
>= else if (temp 50614 && temp <= 50621)
83 {
The return "O";
85}
' Else if ' (temp >= 50622 && temp <= 50905)
87 {
The return "P";
89}
' Else if ' (temp >= 50906 && temp <= 51386)
91 {
"Q";
93}
>= else if (temp 51387 && temp <= 51445)
95 {
return "R";
97}
+ Else if (temp >= 51446 && temp <= 52217)
99 {
return "S";
101}
102 Else if (temp >= 52218 && temp <= 52697)
103 {
The return "T";
105}
The ' if ' (temp >= 52698 && temp <= 52979)
107 {
108 return "W";
109}
' Else if ' (temp >= 52980 && temp <= 53688)
111 {
112 return "X";
113}
114 Else if (temp >= 53689 && temp <= 54480)
115 {
116 return "Y";
117}
118 Else if (temp >= 54481 && temp <= 62289)
119 {
The return "Z";
121}
122 Else
123 {
124 return c.tostring ();
125}
126}
127}
128}
129

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.