using TinyPinyin; namespace YieldChain.Helpers { /// /// 拼音帮助类 /// public class PingYinHelper { /// /// 汉字转拼音(注意:银行需要优化) /// public static string GetPinYin(string strChinese) { if (string.IsNullOrWhiteSpace(strChinese)) { return string.Empty; } //注意:银行需要优化 //注意:英文字母不会转大写 return PinyinHelper.GetPinyin(strChinese); } /// /// 汉字转拼音 /// public static string GetPinYin(string strChinese, string separator) { if (string.IsNullOrWhiteSpace(strChinese)) { return string.Empty; } if (separator is null) { separator = string.Empty; } //注意:银行需要优化 //注意:英文字母不会转大写 return PinyinHelper.GetPinyin(strChinese, separator); } /// /// 汉字转拼音首字母 /// public static string GetFirstPinYin(string strChinese) { if (string.IsNullOrWhiteSpace(strChinese)) { return string.Empty; } //注意:银行需要优化 //注意:英文字母不会转大写 return PinyinHelper.GetPinyinInitials(strChinese); } /// /// 汉字转拼音首字母 /// 处理了"银行","分行","支行","总行" /// public static string GetFirstPinYin_Enhance(string strChinese) { if (string.IsNullOrWhiteSpace(strChinese)) { return string.Empty; } string pinyin = PinyinHelper.GetPinyin(strChinese, "|"); pinyin = pinyin .Replace("YIN|XING", "YIN|HANG") .Replace("FEN|XING", "FEN|HANG") .Replace("ZHI|XING", "ZHI|HANG") .Replace("ZHONG|XING", "ZHONG|HANG"); return string.Join("", (from x in pinyin.Split('|') select x.Substring(0, 1)).ToArray()); } } }