下载完毕后,进行解压,里面有7个msi文件,其中:CHSPinYinConv.msi就是汉字拼音相关的,CHTCHSConv.msi是进行 简体与繁体进行相互转换的,值安装这2个msi即可。安装完毕后,需要在VS里添加引用,分别引用:C:\Program Files\Microsoft Visual Studio International Pack\Simplified Chinese Pin-Yin Conversion Library下和C:\Program Files\Microsoft Visual Studio International Pack\Traditional Chinese to Simplified Chinese Conversion Library and Add-In Tool下的dll即可使用。
代码:
using Microsoft.International.Converters.PinYinConverter;
using Microsoft.International.Converters.TraditionalChineseToSimplifiedConverter;
public static string GetPinyin(string str)
{
string r = string.Empty;
foreach (char obj in str)
{
try
{
ChineseChar chineseChar = new ChineseChar(obj);
string t = chineseChar.Pinyins[0].ToString();
r += t.Substring(0, t.Length - 1);
}
catch
{
r += obj.ToString();
}
}
return r;
}
public static string GetShortPinyin(string str)
{
string r = string.Empty;
foreach (char obj in str)
{
try
{
ChineseChar chineseChar = new ChineseChar(obj);
string t = chineseChar.Pinyins[0].ToString();
r += t.Substring(0, 1);
}
catch
{
r += obj.ToString();
}
}
return r;
}
调用:
GetPinyin("全拼 瘦痩龙");
GetShortPinyin("首字符 瘦痩龙");
可以使用Microsoft Visual Studio International Pack 1.0 Service Release 1
其包括CHSPinYinConv.msi,即中文汉字与拼音的转换中间件.还有日文,繁体中文等等.