A simple method to obtain the first letter of Chinese Characters in C #
Source: Internet
Author: User
The simple method is to get the first letter of Chinese Characters in C #-Linux general technology-Linux programming and kernel information. The following is a detailed description. Today, I saw a "C # Calculate Chinese pinyin code" on the Blog of yyf9989. I thought it was complicated to read the code. It mainly retrieves the position of the input Chinese characters in the array and returns the first letter. So I remembered that I could use the Chinese character encoding in the computer to get the first Pinyin of the Chinese character. I found some information and solved it through the following methods. Put it here for your reference.
Static public string GetChineseSpell (string strText)
{
Int len = strText. Length;
String myStr = "";
For (int I = 0; I
{
MyStr + = getSpell (strText. Substring (I, 1 ));
}
Return myStr;
}
Static public string getSpell (string cnChar)
{
Byte [] arrCN = Encoding. Default. GetBytes (cnChar );
If (arrCN. Length> 1)
{
Int area = (short) arrCN [0];
Int pos = (short) arrCN [1];
Int code = (area <8) + pos;
Int [] areacode = {45217,45253, 45761,46318, 46826,47010, 47297,47614, 48119,48119, 49062,
49324,49896, 50371,50614, 50622,50906, 51387,51446, 52218,52698, 52698,52698, 52980,53689,
54481 };
For (int I = 0; I <26; I ++)
{
Int max = 55290;
If (I! = 25) max = areacode [I + 1];
If (areacode <= Code & code
{
Return Encoding. Default. GetString (new byte [] {(byte) (65 + I )});
}
}
Return "*";
}
Else return cnChar;
}
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