81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using TinyPinyin;
|
|
|
|
namespace YieldChain.Helpers
|
|
{
|
|
/// <summary>
|
|
/// 拼音帮助类
|
|
/// </summary>
|
|
public class PingYinHelper
|
|
{
|
|
/// <summary>
|
|
/// 汉字转拼音(注意:银行需要优化)
|
|
/// </summary>
|
|
public static string GetPinYin(string strChinese)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(strChinese))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
//注意:银行需要优化
|
|
//注意:英文字母不会转大写
|
|
return PinyinHelper.GetPinyin(strChinese);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 汉字转拼音
|
|
/// </summary>
|
|
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);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 汉字转拼音首字母
|
|
/// </summary>
|
|
public static string GetFirstPinYin(string strChinese)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(strChinese))
|
|
{
|
|
return string.Empty;
|
|
}
|
|
|
|
//注意:银行需要优化
|
|
//注意:英文字母不会转大写
|
|
return PinyinHelper.GetPinyinInitials(strChinese);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 汉字转拼音首字母
|
|
/// <para>处理了"银行","分行","支行","总行"</para>
|
|
/// </summary>
|
|
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());
|
|
}
|
|
}
|
|
}
|