初步更新文章栏目路径功能
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
using Microsoft.International.Converters.PinYinConverter;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COMCMS.Common
|
||||
{
|
||||
public class PinYinHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 默认编码
|
||||
/// </summary>
|
||||
//private static Encoding gb2312 = Encoding.GetEncoding("GB2312");
|
||||
|
||||
#region 汉字转化为拼音
|
||||
/// <summary>
|
||||
/// 汉字转化为拼音
|
||||
/// </summary>
|
||||
/// <param name="str">汉字</param>
|
||||
/// <returns>全拼</returns>
|
||||
public static string GetPinyin(string str)
|
||||
{
|
||||
string r = string.Empty;
|
||||
foreach (char obj in str)
|
||||
{
|
||||
try
|
||||
{
|
||||
ChineseChar chineseChar = new ChineseChar(obj);
|
||||
string t = chineseChar.Pinyins[0].ToString();
|
||||
r += t.Substring(0, t.Length - 1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
r += obj.ToString();
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 汉字转化为拼音首字母
|
||||
/// <summary>
|
||||
/// 汉字转化为拼音首字母
|
||||
/// </summary>
|
||||
/// <param name="str">汉字</param>
|
||||
/// <returns>首字母</returns>
|
||||
public static string GetFirstPinyin(string str)
|
||||
{
|
||||
string r = string.Empty;
|
||||
foreach (char obj in str)
|
||||
{
|
||||
try
|
||||
{
|
||||
ChineseChar chineseChar = new ChineseChar(obj);
|
||||
string t = chineseChar.Pinyins[0].ToString();
|
||||
r += t.Substring(0, 1);
|
||||
}
|
||||
catch
|
||||
{
|
||||
r += obj.ToString();
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user