WPF汉字转拼音
- NuGet安装:
- Microsoft.International.Converters.PinYinConverter
string str = "码农E+";
string py = "";
foreach (char item in str.ToCharArray())
{
if (Microsoft.International.Converters.PinYinConverter.ChineseChar.IsValidChar(item))
{
ChineseChar cc = new ChineseChar(item);
py+= cc.Pinyins[0].ToUpper() +" ";
}
else
{
py+= item.ToString()+" ";
}
}
Console.WriteLine(py);
// 输出: MA3 NONG2 E +
//(拼音后面的数字是拼音声调)