VS Nuget 上 搜索 NPinyin, 会有好几个选择
经过测试
NPinyin 等都不好用, 好些汉字 无法转拼音, 比如 "洺","玥" 等等,
只有 NPinyinPro 可以!
测试代码:
public void PingyinTest() { Dictionary<string, Tuple<string, string>> dict = new Dictionary<string, Tuple<string, string>>() { {"梅钰", new Tuple<string,string>("meiyu","MY")}, {"张洺", new Tuple<string,string>("zhangming","ZM")}, {"王玥", new Tuple<string,string>("wangyue","WY")}, {"王思琪", new Tuple<string,string>("wangsiqi","WSQ")}, {"董云强", new Tuple<string,string>("dongyunqiang","DYQ")}, {"宋红培", new Tuple<string,string>("songhongpei","SHP")}, {"石磊", new Tuple<string,string>("shilei","SL")}, }; foreach (var keyval in dict) { var name = keyval.Key; var full = keyval.Value.Item1; var first = keyval.Value.Item2; var py = NPinyin.Pinyin.GetPinyin(name).Replace(" ", ""); var pf = NPinyin.Pinyin.GetInitials(name); Console.WriteLine($"{name}\t {py} {(py == full ? "==" : "!=")} {full}\t {pf} {(pf == first ? "==" : "!=")} {first}"); } }
标签:比原,keyval,name,Tuple,C#,var,new,NPinyin From: https://www.cnblogs.com/lzpong/p/16968594.html