- 所属分类:独占观点
- 作者: 独占网络
- 更新时间: 2017-6-26 17:24:42
- 返回列表
/// <summary>
/// 得到文字的拼音的个字母
/// </summary>
/// <param name="content">传入的文字</param>
/// <returns>返回的字母</returns>
static public string getZiMu(string content)
{
int len = content.Length;
string result = string.Empty;
if (!string.IsNullOrEmpty(content))
{
result += ZiMu(content.Substring(0, 1));
}
return result;
}
/// <summary>
/// 取出拼音信息
/// </summary>
/// <param name="zi">个文字</param>
/// <returns>返回信息字母</returns>
static public string ZiMu(string zi)
{
byte[] pinyin = Encoding.Default.GetBytes(zi);
if (pinyin.Length > 1)
{
int area = (short)pinyin[0];
int pos = (short)pinyin[1];
int code = (area << 8) + pos;
int[] areacode = { 45217, 45253, 45761, 46318, 46826, 47010, 47297, 47614, 48119, 48119, 49062, 49324, 49896, 50371, 50614, 50622, 50906, 51387, 51446, 52218, 52698, 52698, 52698, 52980, 53689, 54481 };
for (int i = 0; i < 26; i++)
{
int max = 55290;
if (i != 25) max = areacode[i + 1];
if (areacode[i] <= code && code < max)
{
return Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "?";
}
else return zi;
}
添加用方法就是 getZiMu("陈");