代码

/// <summary>
/// 在指定的字符串列表CnStr中检索符合拼音索引字符串
/// </summary>
/// <param name="CnStr">汉字字符串</param>
/// <returns>相对应的汉语拼音首字母串</returns>
public static string GetSpellCode(string CnStr)
{
string strTemp = "";
int iLen = CnStr.Length;
int i = 0;

for (i = 0; i <= iLen - 1; i++)
{
strTemp += GetCharSpellCode(CnStr.Substring(i, 1));
}

return strTemp;
}
/// <summary>
/// 得到一个汉字的拼音第一个字母,如果是一个英文字母则直接返回大写字母
/// </summary>
/// <param name="CnChar">单个汉字</param>
/// <returns>单个大写字母</returns>
private static string GetCharSpellCode(string CnChar)
{
long iCnChar;

byte[] ZW = System.Text.Encoding.Default.GetBytes(CnChar);

//如果是字母,则直接返回
if (ZW.Length == 1)
{
return CnChar.ToUpper();
}
else
{
// get the array of byte from the single char
int i1 = (short)(ZW[0]);
int i2 = (short)(ZW[1]);
iCnChar = i1 * 256 + i2;
}

// iCnChar match the constant
if ((iCnChar >= 45217) && (iCnChar <= 45252))
{
return "A";
}
else if ((iCnChar >= 45253) && (iCnChar <= 45760))
{
return "B";
}
else if ((iCnChar >= 45761) && (iCnChar <= 46317))
{
return "C";
}
else if ((iCnChar >= 46318) && (iCnChar <= 46825))
{
return "D";
}
else if ((iCnChar >= 46826) && (iCnChar <= 47009))
{
return "E";
}
else if ((iCnChar >= 47010) && (iCnChar <= 47296))
{
return "F";
}
else if ((iCnChar >= 47297) && (iCnChar <= 47613))
{
return "G";
}
else if ((iCnChar >= 47614) && (iCnChar <= 48118))
{
return "H";
}
else if ((iCnChar >= 48119) && (iCnChar <= 49061))
{
return "J";
}
else if ((iCnChar >= 49062) && (iCnChar <= 49323))
{
return "K";
}
else if ((iCnChar >= 49324) && (iCnChar <= 49895))
{
return "L";
}
else if ((iCnChar >= 49896) && (iCnChar <= 50370))
{
return "M";
}

else if ((iCnChar >= 50371) && (iCnChar <= 50613))
{
return "N";
}
else if ((iCnChar >= 50614) && (iCnChar <= 50621))
{
return "O";
}
else if ((iCnChar >= 50622) && (iCnChar <= 50905))
{
return "P";
}
else if ((iCnChar >= 50906) && (iCnChar <= 51386))
{
return "Q";
}
else if ((iCnChar >= 51387) && (iCnChar <= 51445))
{
return "R";
}
else if ((iCnChar >= 51446) && (iCnChar <= 52217))
{
return "S";
}
else if ((iCnChar >= 52218) && (iCnChar <= 52697))
{
return "T";
}
else if ((iCnChar >= 52698) && (iCnChar <= 52979))
{
return "W";
}
else if ((iCnChar >= 52980) && (iCnChar <= 53640))
{
return "X";
}
else if ((iCnChar >= 53689) && (iCnChar <= 54480))
{
return "Y";
}
else if ((iCnChar >= 54481) && (iCnChar <= 55289))
{
return "Z";
}
else return ("");
}

转载于:https://www.cnblogs.com/delicious28/archive/2010/03/19/1690229.html

根据姓名得到名字首字母相关推荐

  1. 根据中文名字首字母进行分组

    第一步:mysql 按中文名字首字母排序   第二步:循环列表,提取中文首字母 第三步:根据列表首字母进行分组 #mysql 按中文名字首字母排序 ORDER BY CONVERT ( 名字字段 US ...

  2. Java获取名字首字母拼音并按名字拼音分组工具类

    1. maven <dependency><groupId>com.belerweb</groupId><artifactId>pinyin4j< ...

  3. Python实现将不规范的英文名字首字母大写

    Python实现将不规范的英文名字首字母大写 这篇文章给大家主要介绍的是利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.文中给出了三种解决方法,大家可以根据需要选 ...

  4. 获取名字首字母,js

    获取名字首字母用来做默认头像,不多说,直接上代码. formate.js var formate = (function () {var Formate = function (ops) {this. ...

  5. python首字母不能是_Python实现将不规范的英文名字首字母大写

    Python实现将不规范的英文名字首字母大写 这篇文章给大家主要介绍的是利用map()函数,把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.文中给出了三种解决方法,大家可以根据需要选 ...

  6. 拼音开头有什么字_excel查找函数应用:如何提取姓名的拼音首字母

    编按:哈喽,大家好!如果此刻让你快速提取汉字拼音的首字母,你会怎么做呢?相信大多数小伙伴面对这个问题时,都会蒙圈,可能会想"这应该得用VBA解决吧,函数应该不行吧."其实呀,这个问 ...

  7. 汉字姓名怎么取到姓名的汉语拼音首字母

    public class FirstLetterUti {private static int BEGIN = 45217;private static int END = 63486;// 按照声母 ...

  8. Oracle 10g如何对用户姓名,按首字母排序、查询

    2019独角兽企业重金招聘Python工程师标准>>> 首先介绍Oracle 9i新增加的一个系统自带的排序函数 1.按首字母排序 在oracle9i中新增了按照拼音.部首.笔画排序 ...

  9. oracle按照姓名查询,Oracle 10g如何对用户姓名,按首字母排序、查询

    首先介绍Oracle 9i新增加的一个系统自带的排序函数 1.按首字母排序 在oracle9i中新增了按照拼音.部首.笔画排序功能.设置NLS_SORT值 SCHINESE_RADICAL_M   按 ...

最新文章

  1. linux深度定制,Linux Deepin 12.06 beta1 发布
  2. ajax提交不能进入后台_Ajax跨域问题
  3. 解决:未找到setenv命令
  4. python基础第六天
  5. vue中v-for循环如何将变量带入class的属性名中
  6. oninput,onpropertychange,onchange的用法和区别
  7. kivy中文手册python_K-Meleon
  8. mysqldump原理及实验
  9. 10款你应该了解的开源安全工具
  10. gsp 页面 html.dat,grails2.3.x在gsp显示html
  11. 知云文献翻译打不开_推荐一个很好用的阅读英文文献工具(研究僧看过来啦!!!)...
  12. 用java swing写的一个显示时间和实时天气的小程序
  13. 深度解读|盘扣销售价格上涨背后的原因是什么?
  14. python turtle渐变色_Python : turtle色彩控制实例详解
  15. 游戏修改器制作教程三:内存与Cheat Engine
  16. html 中的版权符号 : 圆圈C
  17. 计算机视觉编程 BOF图像检索(Python)
  18. 小米note3android8.0,小米Note3 lineage16 安卓9.0 极致省电 纯净 完美root Xposed 经典版...
  19. HDU6438(贪心技巧)
  20. 盘古石杯电子取证比赛WP

热门文章

  1. 将MathType公式转换为Word自带公式
  2. caffe 练习1:training LeNet on MNIST with Caffe/ 用LeNet识别手写字符集 Mnist------by 香蕉麦乐迪
  3. 谱聚类(spectral clustering)理解
  4. htmlparser设置表单属性值
  5. 欧蓝德 (660) -(警车内被乔丹体育)_几款豪华SUV的油耗与空间的巅峰对决!欧蓝德还是奇骏...
  6. SQL Server2019数据库查询所有数据库名、表名、表结构、表字段、主键方法演示,执行sql提示对象名‘user_tab_columns‘、 ‘user_cons_columns‘ 无效问题解决
  7. Python 技巧篇-字符串灵活处理:字符串过滤、字符串拼接,字符串切片,特殊、超长字符串的处理实例演示
  8. Python 技巧篇 - 英文单词首字母大小写转换功能实例演示,字符串切片实现
  9. Python 利用pickle库查看pkl文件实例演示,pkl是什么类型的文件?怎么来打开它?
  10. 在小程序开发路上踩过的小坑