C# 获取汉字的拼音首字母
/// <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 ("?");
}
C# 获取汉字的拼音首字母的更多相关文章
- (转载)delphi中获取汉字的拼音首字母
delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...
- sql获取汉字的拼音首字母的函数
ql获取汉字的拼音首字母 if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and ...
- C# 获取汉字的拼音首字母和全拼(含源码)
C# 获取汉字的拼音首字母 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手 ...
- 获取汉字的拼音首字母--pinyin
var pinyin = (function (){ var Pinyin = function (ops){ this.initialize(ops); }, options = { checkPo ...
- sql获取汉字的拼音首字母
if exists (select * from sysobjects where id = object_id(N'[fn_ChineseToSpell]') and xtype in (N'FN' ...
- SqlServer 笔记二 获取汉字的拼音首字母
一.该函数传入字符串,返回数据为:如果为汉字字符,返回该字符的首字母,如果为非汉字字符,则返回本身. 二.用到的知识点:汉字对应的UNICODE值,汉字的排序规则. 三.数据库函数: )) ) AS ...
- SqlServer 获取汉字的拼音首字母
一.该函数传入字符串,返回数据为:如果为汉字字符,返回该字符的首字母,如果为非汉字字符,则返回本身.二.用到的知识点:汉字对应的UNICODE值,汉字的排序规则.三.数据库函数: CREATE FUN ...
- C#获取包括一二级汉字的拼音 首字母
C#获取包括一二级汉字的拼音 首字母 声母 汉字拼音转换 using System; using System.Collections.Generic; using System.Linq; usin ...
- js汉字转拼音首字母
js汉字转拼音首字母 2018-04-09 阅读 1018 收藏 1 原链:segmentfault.com 分享到: 前端必备图书<JavaScript设计模式与开发实践> > ...
随机推荐
- java 简单矩阵乘法运算
1.计算的两个矩阵其中第一个矩阵的列数必须和第二个矩阵的行数一致(或者反过来): 2.第一个矩阵的行数决定了结果矩阵的行数,第二个矩阵的列数决定了结果矩阵的列数: package org.admln. ...
- 安卓Design包之CoordinatorLayout配合AppBarLayout,ToolBar,TabLaout的使用
转载: CoordinatorLayout配合AppBarLayout,Toolbar和TabLayout的使用 控件的简单介绍: AppBarLayout:它是继承LinerLayout实现的一个V ...
- Liunx UID and GID
一个文件都有一个所有者, 表示该文件是谁创建的. 同时, 该文件还有一个组编号, 表示该文件所属的组, 一般为文件所有者所属的组. 如果是一个可执行文件, 那么在执行时, 一般该文件只拥有调用该文件的 ...
- codeforces 676A A. Nicholas and Permutation(水题)
题目链接: A. Nicholas and Permutation time limit per test 1 second memory limit per test 256 megabytes i ...
- 初识 Asp.Net内置对象之Session对象
Session对象 Session对象用于存储在多个页面调用之间特定用户的信息.Session对象只针对单一网站使用者,不同的客户端无法相互访问.Session对象中止联机机器离现时,,也就是当网站使 ...
- 1154 能量项链[区间dp]
1154 能量项链 2006年NOIP全国联赛提高组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 在Ma ...
- JavaScript--正则表达式(笔记)
一 什么是正则表达式 // 正则表达式(regular expression)是一个描述字符模式的对象; // JS定义RegExp类表示正则表达式; // String和RegExp都定义了使用正则 ...
- Lazy Makes Others Busy – a bad experience with DLL
The Story: Recently, I’m working as a deployment engineer at customer site with my team members. The ...
- Part 14 Mathematical functions in sql server
Part 29 Mathematical functions in sql server
- Linux命令(2):ls命令
1.作用:列出目录的内容: 2.格式:ls [选项] [文件] [选项]为指定要查看文件相关的内容,若未指定文件默认查看当前目录下的所有文件: 3.常见参数: 如图: 4.使用实例: [yournam ...