Code
1static public string GetChineseSpell(string strText)
2{
3int len = strText.Length;
4string myStr = "";
5for(int i=0;i<len;i++)
6{
7myStr += getSpell(strText.Substring(i,1));
8}
9return myStr;
10}
11
12
13
14static public string getSpell(string cnChar)
15{
16byte[] arrCN = Encoding.Default.GetBytes(cnChar);
17if(arrCN.Length > 1)
18{
19int area = (short)arrCN[0];
20int pos = (short)arrCN[1];
21int code = (area<<8) + pos;
22int[] 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};
23for(int i=0;i<26;i++)
24{
25int max = 55290;
26if(i != 25) max = areacode[i+1];
27if(areacode[i]<=code && code<max)
28{
29return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
30}
31}
32return "*";
33}
34else return cnChar;
35}
36
1static public string GetChineseSpell(string strText)
2{
3int len = strText.Length;
4string myStr = "";
5for(int i=0;i<len;i++)
6{
7myStr += getSpell(strText.Substring(i,1));
8}
9return myStr;
10}
11
12
13
14static public string getSpell(string cnChar)
15{
16byte[] arrCN = Encoding.Default.GetBytes(cnChar);
17if(arrCN.Length > 1)
18{
19int area = (short)arrCN[0];
20int pos = (short)arrCN[1];
21int code = (area<<8) + pos;
22int[] 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};
23for(int i=0;i<26;i++)
24{
25int max = 55290;
26if(i != 25) max = areacode[i+1];
27if(areacode[i]<=code && code<max)
28{
29return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
30}
31}
32return "*";
33}
34else return cnChar;
35}
36