Code
1
static public string GetChineseSpell(string strText)
2![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
{
3
int len = strText.Length;
4
string myStr = "";
5
for(int i=0;i<len;i++)
6![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
7
myStr += getSpell(strText.Substring(i,1));
8
}
9
return myStr;
10
}
11![None.gif](/Images/OutliningIndicators/None.gif)
12
13![None.gif](/Images/OutliningIndicators/None.gif)
14
static public string getSpell(string cnChar)
15![ExpandedBlockStart.gif](/Images/OutliningIndicators/ExpandedBlockStart.gif)
![ContractedBlock.gif](/Images/OutliningIndicators/ContractedBlock.gif)
{
16
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
17
if(arrCN.Length > 1)
18![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
19
int area = (short)arrCN[0];
20
int pos = (short)arrCN[1];
21
int code = (area<<8) + pos;
22![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
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};
23
for(int i=0;i<26;i++)
24![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
25
int max = 55290;
26
if(i != 25) max = areacode[i+1];
27
if(areacode[i]<=code && code<max)
28![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![ContractedSubBlock.gif](/Images/OutliningIndicators/ContractedSubBlock.gif)
{
29![ExpandedSubBlockStart.gif](/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
return Encoding.Default.GetString(new byte[]
{(byte)(65+i)});
30
}
31
}
32
return "*";
33
}
34
else return cnChar;
35
}
36
转载于:https://www.cnblogs.com/zhangchenliang/archive/2008/01/08/1030314.html