You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
845 B
34 lines
845 B
using Microsoft.International.Converters.PinYinConverter;
|
|
|
|
namespace Common.Helper.StringText
|
|
{
|
|
/// <summary>
|
|
/// 拼音帮助类
|
|
/// </summary>
|
|
public class PinYinHelper
|
|
{
|
|
/// <summary>
|
|
/// 获取首字母
|
|
/// </summary>
|
|
/// <param name="str"></param>
|
|
/// <returns></returns>
|
|
public static string GetFirstPinyin(string str)
|
|
{
|
|
var r = string.Empty;
|
|
foreach (var obj in str)
|
|
{
|
|
try
|
|
{
|
|
var chineseChar = new ChineseChar(obj);
|
|
var t = chineseChar.Pinyins[0];
|
|
r += t[..1];
|
|
}
|
|
catch
|
|
{
|
|
r += obj.ToString();
|
|
}
|
|
}
|
|
return r;
|
|
}
|
|
}
|
|
}
|
|
|