Obtain the first spelling of a Chinese String

Source: Internet
Author: User

Public static string getfirstletter (string Str)
{
Char T1;
String val = "";
For (INT I = 0; I <Str. Trim (). length; I ++)
{
T1 = convert. tochar (Str. Trim (). substring (I, 1 ));
If (ASCII (T1)> = ASCII ('! ') & ASCII (T1) <= ASCII ('~ '))
Val + = T1;
Else if (ASCII (T1)> = ASCII ('Ah') & ASCII (T1) <ASCII ('bar '))
Val + = "";
Else if (ASCII (T1)> = ASCII ('bar') & ASCII (T1) <ASCII ('eras '))
Val + = "B ";
Else if (ASCII (T1)> = ASCII ('erase') & ASCII (T1) <ASCII ('tag '))
Val + = "C ";
Else if (ASCII (T1)> = ASCII ('to') & ASCII (T1) <ASCII ('Moth '))
Val + = "D ";
Else if (ASCII (T1)> = ASCII ('Moth ') & ASCII (T1) <ASCII ('fat '))
Val + = "E ";
Else if (ASCII (T1)> = ASCII ('fout') & ASCII (T1) <ASCII ('shanghai '))
Val + = "F ";
Else if (ASCII (T1)> = ASCII ('hangzhou') & ASCII (T1) <ASCII ('har '))
Val + = "G ";
Else if (ASCII (T1)> = ASCII ('har') & ASCII (T1) <ASCII ('click '))
Val + = "H ";
Else if (ASCII (T1)> = ASCII ('click') & ASCII (T1) <ASCII ('case '))
Val + = "J ";
Else if (ASCII (T1)> = ASCII ('case') & ASCII (T1) <ASCII ('late '))
Val + = "K ";
Else if (ASCII (T1)> = ASCII ('late') & ASCII (T1) <ASCII ('Ma '))
Val + = "L ";
Else if (ASCII (T1)> = ASCII ('Ma') & ASCII (T1) <ASCII ('Ta '))
Val + = "M ";
Else if (ASCII (T1)> = ASCII ('A') & ASCII (T1) <ASCII ('oh '))
Val + = "N ";
Else if (ASCII (T1)> = ASCII ('Oh ') & ASCII (T1) <ASCII ('Pa '))
Val + = "O ";
Else if (ASCII (T1)> = ASCII ('Pa ') & ASCII (T1) <ASCII ('period '))
Val + = "p ";
Else if (ASCII (T1)> = ASCII ('period ') & ASCII (T1) <ASCII ('ran '))
Val + = "Q ";
Else if (ASCII (T1)> = ASCII ('ran') & ASCII (T1) <ASCII ('za '))
Val + = "R ";
Else if (ASCII (T1)> = ASCII ('za') & ASCII (T1) <ASCII ('collapsing '))
Val + = "S ";
Else if (ASCII (T1)> = ASCII ('collapsing ') & ASCII (T1) <ASCII ('digging '))
Val + = "T ";
Else if (ASCII (T1)> = ASCII ('dig ') & ASCII (T1) <ASCII ('x '))
Val + = "W ";
Else if (ASCII (T1)> = ASCII ('seg') & ASCII (T1) <ASCII ('Pressure '))
Val + = "X ";
Else if (ASCII (T1)> = ASCII ('Press ') & ASCII (T1) <ASCII ('za '))
Val + = "Y ";
Else if (ASCII (T1)> = ASCII ('za '))
Val + = "Z ";
Else
Val + = "-";
}
Return val;
}

Public static int ASCII (char CHR)
{
System. Text. Encoding ecode = system. Text. encoding. getencoding ("gb18030 ");
Byte [] codebytes = ecode. getbytes (CHR. tostring (). Trim ());
If (codebytes. Length = 2)
{
Return (INT) codebytes [0] * 256 + (INT) codebytes [1]-65536;
}
Else
{
Return (INT) codebytes [0];
}
}

This article Reprinted from the network base camp: http://www.xrss.cn/Info/12396.Html

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.