得到汉字首字母

ContractedBlock.gif ExpandedBlockStart.gif Code
 1None.gifstatic public string GetChineseSpell(string strText)
 2ExpandedBlockStart.gifContractedBlock.gifdot.gif{
 3InBlock.gifint len = strText.Length;
 4InBlock.gifstring myStr = "";
 5InBlock.giffor(int i=0;i<len;i++)
 6ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
 7InBlock.gifmyStr += getSpell(strText.Substring(i,1));
 8ExpandedSubBlockEnd.gif}

 9InBlock.gifreturn myStr;
10ExpandedBlockEnd.gif}

11None.gif
12None.gif 
13None.gif
14None.gifstatic public string getSpell(string cnChar)
15ExpandedBlockStart.gifContractedBlock.gifdot.gif{
16InBlock.gifbyte[] arrCN = Encoding.Default.GetBytes(cnChar);
17InBlock.gifif(arrCN.Length > 1)
18ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
19InBlock.gifint area = (short)arrCN[0];
20InBlock.gifint pos = (short)arrCN[1];
21InBlock.gifint code = (area<<8+ pos;
22ExpandedSubBlockStart.gifContractedSubBlock.gifint[] areacode  = dot.gif{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};
23InBlock.giffor(int i=0;i<26;i++)
24ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
25InBlock.gifint max = 55290;
26InBlock.gifif(i != 25) max = areacode[i+1];
27InBlock.gifif(areacode[i]<=code && code<max)
28ExpandedSubBlockStart.gifContractedSubBlock.gifdot.gif{
29ExpandedSubBlockStart.gifContractedSubBlock.gifreturn Encoding.Default.GetString(new byte[]dot.gif{(byte)(65+i)});
30ExpandedSubBlockEnd.gif}

31ExpandedSubBlockEnd.gif}

32InBlock.gifreturn "*";
33ExpandedSubBlockEnd.gif}

34InBlock.gifelse return cnChar;
35ExpandedBlockEnd.gif}

36None.gif

转载于:https://www.cnblogs.com/zhangchenliang/archive/2008/01/08/1030314.html

猜你喜欢

转载自blog.csdn.net/weixin_34227447/article/details/93495958