/// <summary>
/// 获得字符串首字符字母(大写);
/// </summary>
/// <param name="cnChar"></param>
/// <returns></returns>
public string GetStringFirstSpell(string cnChar)
{
//除字母、数字、汉字以外的返回"*"
var result = "*"; if (string.IsNullOrEmpty(cnChar.Trim()))
return result; cnChar = cnChar.Trim().Substring(, );
byte[] arrCn = Encoding.Default.GetBytes(cnChar); //首字为字符,占一个字节
if (arrCn.Length <= )
{
//大写英文字母
if ((short)arrCn[] >= && (short)arrCn[] <= )
return cnChar; //小写英文字母
if (arrCn[] >= && arrCn[] <= )
return Encoding.Default.GetString(new byte[] { (byte)((short)arrCn[] - ) }); //数字
switch (cnChar)
{
case "":
result = "Y";
break;
case "":
result = "E";
break;
case "":
case "":
result = "S";
break;
case "":
result = "W";
break;
case "":
case "":
result = "L";
break;
case "":
result = "Q";
break;
case "":
result = "B";
break;
case "":
result = "J";
break;
}
return result;
}
//首字为汉字,占两个字节
else
{
int area = (short)arrCn[];
int pos = (short)arrCn[];
int code = (area << ) + pos;
int[] areacode = { , , , , , , , , , , , , , , , , , , , , , , , , , };
for (int i = ; i < ; i++)
{
int max = ;
if (i != ) max = areacode[i + ];
if (areacode[i] <= code && code < max)
{
return Encoding.Default.GetString(new byte[] { (byte)( + i) });
}
}
return result;
}
}

有时候需要对汉字获取其拼音首字母,可以用以上的方法。

最新文章

  1. 深入理解脚本化CSS系列第二篇——查询计算样式
  2. bzoj violet系列 (2708~2725)
  3. 转 Microsoft&#39;s Objective-C tech started on BlackBerryOS, Tizen
  4. 这些HTML、CSS知识点,面试和平时开发都需要 No5-No7
  5. aperm方法
  6. 使用J2SE API读取Properties文件的六种方法
  7. springmvc(1)--配置
  8. IIS中的Application.CommonAppDataPath
  9. .net Web.Config配置文件 转
  10. video标签 拖动 转自w3school
  11. An internal error occurred during: &quot;Retrieving archetypes:&quot;. GC overhead limit exceeded
  12. hashmap源码研究
  13. vs 2017 打开 iis express问题
  14. 使用eclipse创建web项目的项目图文步骤
  15. AD 16 下绘图的几个技巧
  16. 会话(Session)与cookies
  17. deep learning自学知识积累笔记
  18. (1.1)mysql 选择合适的数据类型
  19. C#线程篇---解答线程之惑(2)
  20. Vuex深入理解

热门文章

  1. 报错apachectl restart
  2. [51nod1384]全排列
  3. Impala介绍
  4. 1、Question: prep_reads.info vs. align_summary.txt
  5. 使用python已知平均数求随机数
  6. 【Java】ServiceLoader源码分析
  7. Word课程笔记(秋叶系列课程)
  8. 如何从git上clone一个项目
  9. (四)从输入URL到页面加载发生了什么
  10. React中的高阶组件