汉字到拼音转换

安装:CHSPinYinConv,
 导入CHSPinYinConv.dll,
 引入空间using Microsoft.International.Converters.PinYinConverter;
   

View Code
 1 //汉字转拼音

 2         static string GetPinYin(string strCHS) 

 3         {

 4             char[] myChar = strCHS.ToCharArray();

 5             string strOK = "";

 6             //遍历转换

 7             for (int i = 0; i < myChar.Length; i++)

 8             {

 9           //如果可以转换

10                 if (ChineseChar.IsValidChar(myChar[i]))

11                 {

12                     ChineseChar chineseChar = new ChineseChar(myChar[i]);

13                     string s = chineseChar.Pinyins[0].ToString();

14                      //拼音带有音标(1,2,3,4,5)             strOK += s.TrimEnd('1', '2', '3', '4', '5').ToLower() + " ";

15                 }

16                 else

17                 {

18                     strOK += myChar[i].ToString();

19                 }

20             }

21             return strOK;

22         }

23 

24   

 

你可能感兴趣的:(转换)