在实现拼音检索功能前需要引入两个程序集,ChnCharInfo.dll和ChnCharInfo.resources.dll
例如:
1 namespace 拼音检索 2 3 { 4 5 class Program 6 7 { 8 9 static void Main(string[] args) 10 11 { 12 13 Console.WriteLine("请输入一句中文"); 14 15 string str = Console.ReadLine(); 16 17 StringBuilder sb = new StringBuilder(); 18 19 foreach (char item in str) 20 21 { 22 23 if (ChineseChar.IsValidChar(item)) 24 25 { 26 27 ChineseChar ch = new ChineseChar(item); 28 29 30 31 sb.Append(ch.Pinyins[0].Substring(0, ch.Pinyins[0].Length - 1)); 32 33 34 35 } 36 37 else 38 39 { 40 41 sb.Append(item); 42 43 } 44 45 } 46 47 Console.WriteLine(sb.ToString()); 48 49 Console.ReadKey(); 50 51 } 52 53 } 54 55 }