115 lines
3.6 KiB
C#
115 lines
3.6 KiB
C#
|
|
using APT.Infrastructure.Core;
|
|||
|
|
using System;
|
|||
|
|
using System.Text;
|
|||
|
|
|
|||
|
|
namespace APT.Infrastructure.EF
|
|||
|
|
{
|
|||
|
|
public static class AcronymHelper
|
|||
|
|
{
|
|||
|
|
// private static Encoding gb2312 = Encoding.GetEncoding("GB2312");
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 汉字转全拼
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strChinese"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string ConvertToAllSpell(string strChinese)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (strChinese.Length != 0)
|
|||
|
|
{
|
|||
|
|
StringBuilder fullSpell = new StringBuilder();
|
|||
|
|
for (int i = 0; i < strChinese.Length; i++)
|
|||
|
|
{
|
|||
|
|
var chr = strChinese[i];
|
|||
|
|
fullSpell.Append(GetSpell(chr));
|
|||
|
|
}
|
|||
|
|
return fullSpell.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
LoggerManager.GetLogger().Info("全拼转化出错!" + e.Message);
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 汉字转首字母
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="strChinese"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string ConvertToFirstSpell(string strChinese)
|
|||
|
|
{
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
if (strChinese.Length != 0)
|
|||
|
|
{
|
|||
|
|
StringBuilder fullSpell = new StringBuilder();
|
|||
|
|
for (int i = 0; i < strChinese.Length; i++)
|
|||
|
|
{
|
|||
|
|
var chr = strChinese[i];
|
|||
|
|
fullSpell.Append(GetSpell(chr)[0]);
|
|||
|
|
}
|
|||
|
|
return fullSpell.ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
catch (Exception e)
|
|||
|
|
{
|
|||
|
|
LoggerManager.GetLogger().Info("首字母转化出错!" + e.Message);
|
|||
|
|
}
|
|||
|
|
return string.Empty;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private static string GetSpell(char chr)
|
|||
|
|
{
|
|||
|
|
//var coverchr = NPinyin.Pinyin.GetPinyin(chr);
|
|||
|
|
//bool isChineses = ChineseChar.IsValidChar(coverchr[0]);
|
|||
|
|
//if (isChineses)
|
|||
|
|
//{
|
|||
|
|
// ChineseChar chineseChar = new ChineseChar(coverchr[0]);
|
|||
|
|
// foreach (string value in chineseChar.Pinyins)
|
|||
|
|
// {
|
|||
|
|
// if (!string.IsNullOrEmpty(value))
|
|||
|
|
// {
|
|||
|
|
// return value.Remove(value.Length - 1, 1);
|
|||
|
|
// }
|
|||
|
|
// }
|
|||
|
|
//}
|
|||
|
|
//return coverchr;
|
|||
|
|
return "";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 数字转换成字母(1-26)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="number"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string NumToChar(int number)
|
|||
|
|
{
|
|||
|
|
number = number + 64;
|
|||
|
|
if (65 <= number && 90 >= number)
|
|||
|
|
{
|
|||
|
|
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
|
|||
|
|
byte[] btNumber = new byte[] { (byte)number };
|
|||
|
|
return asciiEncoding.GetString(btNumber).ToLower();
|
|||
|
|
}
|
|||
|
|
return "数字不在转换范围内";
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 字母转换成数字(1-26)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="str"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public static string CharToNum(char chr)
|
|||
|
|
{
|
|||
|
|
byte[] array = new byte[1];
|
|||
|
|
array = System.Text.Encoding.ASCII.GetBytes(chr.ToString().ToUpper());
|
|||
|
|
int asciicode = (short)(array[0]) - 64;
|
|||
|
|
return Convert.ToString(asciicode);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|