1、利用微软提供的拼音库,计算出汉字的拼音的方法,此方法支持多音字符

  下载 Visual Studio International Pack类库,该类库扩展了.NET Framework对全球化软件开发的支持 

  下载地址:http://www.microsoft.com/downloads/details.aspx?FamilyID=44cac7f0-633b-477d-aed2-99aee642fc10&DisplayLang=zh-cn

  解压得到CHSPinYinConv.msi(拼音类库) 和 CHSPinYinConv.msi(简繁体类),安装(记住安装路径)

  [1]在项目中添加引用,把ChnCharInfo.dll 引入进来

  [2]添加命名空间,

 using Microsoft.International.Converters.PinYinConverter;

  [3]具体用法,

        private string ToPinyin(string hanzi)
{
char[] ch = hanzi.ToArray();
string pinyinStr = "";
foreach (char c in ch)
{
if (ChineseChar.IsValidChar(c))
{
ChineseChar chineseChar = new ChineseChar(c);
ReadOnlyCollection<string> pinyin = chineseChar.Pinyins;
pinyinStr += (pinyin[].Substring(, pinyin[].Length - ));
}
else
{
pinyinStr += c.ToString();
}
}
return pinyinStr.ToLower();
}
05-11 18:17