![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1
2
3 //调用 ConvertLetters(String chinese)方法,传入参数(只要是汉字,则转为大写的英文字母,可自己去定义了)
4
5 public String ConvertLetters(String chineseStr)
6 {
7 try
8 {
9 char[] buffer = new char[chinese.Length];
10 for (int i = 0; i < chinese.Length; i++)
11 {
12 buffer[i] = ConvertChar(chinese[i]);
13 }
14 return new String(buffer).Replace("", "");
15 }
16 catch
17 {
18 return "";
19 }
20 }
21
22 public char ConvertChar(Char chinese)
23 {
24 try
25 {
26 Encoding gb2312 = Encoding.GetEncoding("GB2312");
27 Encoding unicode = Encoding.Unicode;
28 byte[] unicodeBytes = unicode.GetBytes(new Char[] { chinese });
29 byte[] asciiBytes = Encoding.Convert(unicode, gb2312, unicodeBytes);
30 if (asciiBytes.Length < 2)
31 return chinese; //待转换的字符在ascii码表示范围内
32 int n = (int)asciiBytes[0] << 8;
33 n += (int)asciiBytes[1];
34 // 根据汉字区域码获取拼音声母
35 if (In(0xB0A1, 0xB0C4, n)) return 'A';
36 if (In(0XB0C5, 0XB2C0, n)) return 'B';
37 if (In(0xB2C1, 0xB4ED, n)) return 'C';
38 if (In(0xB4EE, 0xB6E9, n)) return 'D';
39 if (In(0xB6EA, 0xB7A1, n)) return 'E';
40 if (In(0xB7A2, 0xB8c0, n)) return 'F';
41 if (In(0xB8C1, 0xB9FD, n)) return 'G';
42 if (In(0xB9FE, 0xBBF6, n)) return 'H';
43 if (In(0xBBF7, 0xBFA5, n)) return 'J';
44 if (In(0xBFA6, 0xC0AB, n)) return 'K';
45 if (In(0xC0AC, 0xC2E7, n)) return 'L';
46 if (In(0xC2E8, 0xC4C2, n)) return 'M';
47 if (In(0xC4C3, 0xC5B5, n)) return 'N';
48 if (In(0xC5B6, 0xC5BD, n)) return 'O';
49 if (In(0xC5BE, 0xC6D9, n)) return 'P';
50 if (In(0xC6DA, 0xC8BA, n)) return 'Q';
51 if (In(0xC8BB, 0xC8F5, n)) return 'R';
52 if (In(0xC8F6, 0xCBF0, n)) return 'S';
53 if (In(0xCBFA, 0xCDD9, n)) return 'T';
54 if (In(0xCDDA, 0xCEF3, n)) return 'W';
55 if (In(0xCEF4, 0xD188, n)) return 'X';
56 if (In(0xD1B9, 0xD4D0, n)) return 'Y';
57 if (In(0xD4D1, 0xD7F9, n)) return 'Z';
58 return '';
59 }
60 catch
61 {
62 return '';
63 }
64 }
65
66 private bool In(int Lp, int Hp, int Value)
67 {
68 return ((Value <= Hp) && (Value >= Lp));
69 }