using Microsoft.International.Converters.PinYinConverter;
//功能:获取汉字字符的每个汉字第一个字符,若是非汉字原样显示出来,需要引用ChnCharInfo.dll文件
public static string ChineseCharToPingyin(string str)
{
if (null == str || str.Length <= 0)
{
return "";
}
StringBuilder sb = new StringBuilder("");
ChineseChar chineseChar = null;
for (int i = 0; i < str.Length; i++)
{
try
{
chineseChar = new ChineseChar(str[i]);
if (null != chineseChar.Pinyins[0] && chineseChar.Pinyins[0].Length > 0)
sb.Append(chineseChar.Pinyins[0][0]);
}
catch
{
sb.Append(str[i]);
}
}
return sb.ToString();
}