c#获取文字全拼音
class Program
{
/// <summary>
/// 获得拼音
/// </summary>
/// <param name="str_Spell">汉字</param>
/// <returns></returns>
public static string GetSpell(string str_Spell)
{ try
{
Hashtable t = GetHashtable(); byte[] btArray = System.Text.Encoding.Default.GetBytes(str_Spell);//System.Text.Encoding.Default要使用跟本地服务器一样的编码格式,否则会出来的跟预期不一样
int p;
StringBuilder ret = new StringBuilder();
for (int i = ; i < btArray.Length; i++)
{
p = (int)btArray[i];
if (p > )
{
p = p * + btArray[++i] - ;
ret.Append(GetString(t, p));
}
else
{
ret.Append((char)p);
}
}
t.Clear();
return ret.ToString();
}
catch
{
return "";
} }
private static string GetString(Hashtable hashtable, int num)
{
if (num < - || num > -)
return "";
while (!hashtable.ContainsKey(num))
num--;
return hashtable[num].ToString();
} private static Hashtable GetHashtable()
{
Hashtable ht = new Hashtable();
ht.Add(-, "a");
ht.Add(-, "ai"); ht.Add(-, "an"); ht.Add(-, "ang");
ht.Add(-, "ao"); ht.Add(-, "ba"); ht.Add(-, "bai");
ht.Add(-, "ban"); ht.Add(-, "bang"); ht.Add(-, "bao");
ht.Add(-, "bei"); ht.Add(-, "ben"); ht.Add(-, "beng");
ht.Add(-, "bi"); ht.Add(-, "bian"); ht.Add(-, "biao");
ht.Add(-, "bie"); ht.Add(-, "bin"); ht.Add(-, "bing");
ht.Add(-, "bo"); ht.Add(-, "bu"); ht.Add(-, "ca");
ht.Add(-, "cai"); ht.Add(-, "can"); ht.Add(-, "cang");
ht.Add(-, "cao"); ht.Add(-, "ce"); ht.Add(-, "ceng");
ht.Add(-, "cha"); ht.Add(-, "chai"); ht.Add(-, "chan");
ht.Add(-, "chang"); ht.Add(-, "chao"); ht.Add(-, "che");
ht.Add(-, "chen"); ht.Add(-, "cheng"); ht.Add(-, "chi");
ht.Add(-, "chong"); ht.Add(-, "chou"); ht.Add(-, "chu");
ht.Add(-, "chuai"); ht.Add(-, "chuan"); ht.Add(-, "chuang");
ht.Add(-, "chui"); ht.Add(-, "chun"); ht.Add(-, "chuo");
ht.Add(-, "ci"); ht.Add(-, "cong"); ht.Add(-, "cou");
ht.Add(-, "cu"); ht.Add(-, "cuan"); ht.Add(-, "cui");
ht.Add(-, "cun"); ht.Add(-, "cuo"); ht.Add(-, "da");
ht.Add(-, "dai"); ht.Add(-, "dan"); ht.Add(-, "dang");
ht.Add(-, "dao"); ht.Add(-, "de"); ht.Add(-, "deng");
ht.Add(-, "di"); ht.Add(-, "dian"); ht.Add(-, "diao");
ht.Add(-, "die"); ht.Add(-, "ding"); ht.Add(-, "diu");
ht.Add(-, "dong"); ht.Add(-, "dou"); ht.Add(-, "du");
ht.Add(-, "duan"); ht.Add(-, "dui"); ht.Add(-, "dun");
ht.Add(-, "duo"); ht.Add(-, "e"); ht.Add(-, "en");
ht.Add(-, "er"); ht.Add(-, "fa"); ht.Add(-, "fan");
ht.Add(-, "fang"); ht.Add(-, "fei"); ht.Add(-, "fen");
ht.Add(-, "feng"); ht.Add(-, "fo"); ht.Add(-, "fou");
ht.Add(-, "fu"); ht.Add(-, "ga"); ht.Add(-, "gai");
ht.Add(-, "gan"); ht.Add(-, "gang"); ht.Add(-, "gao");
ht.Add(-, "ge"); ht.Add(-, "gei"); ht.Add(-, "gen");
ht.Add(-, "geng"); ht.Add(-, "gong"); ht.Add(-, "gou");
ht.Add(-, "gu"); ht.Add(-, "gua"); ht.Add(-, "guai");
ht.Add(-, "guan"); ht.Add(-, "guang"); ht.Add(-, "gui");
ht.Add(-, "gun"); ht.Add(-, "guo"); ht.Add(-, "ha");
ht.Add(-, "hai"); ht.Add(-, "han"); ht.Add(-, "hang");
ht.Add(-, "hao"); ht.Add(-, "he"); ht.Add(-, "hei");
ht.Add(-, "hen"); ht.Add(-, "heng"); ht.Add(-, "hong");
ht.Add(-, "hou"); ht.Add(-, "hu"); ht.Add(-, "hua");
ht.Add(-, "huai"); ht.Add(-, "huan"); ht.Add(-, "huang");
ht.Add(-, "hui"); ht.Add(-, "hun"); ht.Add(-, "huo");
ht.Add(-, "ji"); ht.Add(-, "jia"); ht.Add(-, "jian");
ht.Add(-, "jiang"); ht.Add(-, "jiao"); ht.Add(-, "jie");
ht.Add(-, "jin"); ht.Add(-, "jing"); ht.Add(-, "jiong");
ht.Add(-, "jiu"); ht.Add(-, "ju"); ht.Add(-, "juan");
ht.Add(-, "jue"); ht.Add(-, "jun"); ht.Add(-, "ka");
ht.Add(-, "kai"); ht.Add(-, "kan"); ht.Add(-, "kang");
ht.Add(-, "kao"); ht.Add(-, "ke"); ht.Add(-, "ken");
ht.Add(-, "keng"); ht.Add(-, "kong"); ht.Add(-, "kou");
ht.Add(-, "ku"); ht.Add(-, "kua"); ht.Add(-, "kuai");
ht.Add(-, "kuan"); ht.Add(-, "kuang"); ht.Add(-, "kui");
ht.Add(-, "kun"); ht.Add(-, "kuo"); ht.Add(-, "la");
ht.Add(-, "lai"); ht.Add(-, "lan"); ht.Add(-, "lang");
ht.Add(-, "lao"); ht.Add(-, "le"); ht.Add(-, "lei");
ht.Add(-, "leng"); ht.Add(-, "li"); ht.Add(-, "lia");
ht.Add(-, "lian"); ht.Add(-, "liang"); ht.Add(-, "liao");
ht.Add(-, "lie"); ht.Add(-, "lin"); ht.Add(-, "ling");
ht.Add(-, "liu"); ht.Add(-, "long"); ht.Add(-, "lou");
ht.Add(-, "lu"); ht.Add(-, "lv"); ht.Add(-, "luan");
ht.Add(-, "lue"); ht.Add(-, "lun"); ht.Add(-, "luo");
ht.Add(-, "ma"); ht.Add(-, "mai"); ht.Add(-, "man");
ht.Add(-, "mang"); ht.Add(-, "mao"); ht.Add(-, "me");
ht.Add(-, "mei"); ht.Add(-, "men"); ht.Add(-, "meng");
ht.Add(-, "mi"); ht.Add(-, "mian"); ht.Add(-, "miao");
ht.Add(-, "mie"); ht.Add(-, "min"); ht.Add(-, "ming");
ht.Add(-, "miu"); ht.Add(-, "mo"); ht.Add(-, "mou");
ht.Add(-, "mu"); ht.Add(-, "na"); ht.Add(-, "nai");
ht.Add(-, "nan"); ht.Add(-, "nang"); ht.Add(-, "nao");
ht.Add(-, "ne"); ht.Add(-, "nei"); ht.Add(-, "nen");
ht.Add(-, "neng"); ht.Add(-, "ni"); ht.Add(-, "nian");
ht.Add(-, "niang"); ht.Add(-, "niao"); ht.Add(-, "nie");
ht.Add(-, "nin"); ht.Add(-, "ning"); ht.Add(-, "niu");
ht.Add(-, "nong"); ht.Add(-, "nu"); ht.Add(-, "nv");
ht.Add(-, "nuan"); ht.Add(-, "nue"); ht.Add(-, "nuo");
ht.Add(-, "o"); ht.Add(-, "ou"); ht.Add(-, "pa");
ht.Add(-, "pai"); ht.Add(-, "pan"); ht.Add(-, "pang");
ht.Add(-, "pao"); ht.Add(-, "pei"); ht.Add(-, "pen");
ht.Add(-, "peng"); ht.Add(-, "pi"); ht.Add(-, "pian");
ht.Add(-, "piao"); ht.Add(-, "pie"); ht.Add(-, "pin");
ht.Add(-, "ping"); ht.Add(-, "po"); ht.Add(-, "pu");
ht.Add(-, "qi"); ht.Add(-, "qia"); ht.Add(-, "qian");
ht.Add(-, "qiang"); ht.Add(-, "qiao"); ht.Add(-, "qie");
ht.Add(-, "qin"); ht.Add(-, "qing"); ht.Add(-, "qiong");
ht.Add(-, "qiu"); ht.Add(-, "qu"); ht.Add(-, "quan");
ht.Add(-, "que"); ht.Add(-, "qun"); ht.Add(-, "ran");
ht.Add(-, "rang"); ht.Add(-, "rao"); ht.Add(-, "re");
ht.Add(-, "ren"); ht.Add(-, "reng"); ht.Add(-, "ri");
ht.Add(-, "rong"); ht.Add(-, "rou"); ht.Add(-, "ru");
ht.Add(-, "ruan"); ht.Add(-, "rui"); ht.Add(-, "run");
ht.Add(-, "ruo"); ht.Add(-, "sa"); ht.Add(-, "sai");
ht.Add(-, "san"); ht.Add(-, "sang"); ht.Add(-, "sao");
ht.Add(-, "se"); ht.Add(-, "sen"); ht.Add(-, "seng");
ht.Add(-, "sha"); ht.Add(-, "shai"); ht.Add(-, "shan");
ht.Add(-, "shang"); ht.Add(-, "shao"); ht.Add(-, "she");
ht.Add(-, "shen"); ht.Add(-, "sheng"); ht.Add(-, "shi");
ht.Add(-, "shou"); ht.Add(-, "shu"); ht.Add(-, "shua");
ht.Add(-, "shuai"); ht.Add(-, "shuan"); ht.Add(-, "shuang");
ht.Add(-, "shui"); ht.Add(-, "shun"); ht.Add(-, "shuo");
ht.Add(-, "si"); ht.Add(-, "song"); ht.Add(-, "sou");
ht.Add(-, "su"); ht.Add(-, "suan"); ht.Add(-, "sui");
ht.Add(-, "sun"); ht.Add(-, "suo"); ht.Add(-, "ta");
ht.Add(-, "tai"); ht.Add(-, "tan"); ht.Add(-, "tang");
ht.Add(-, "tao"); ht.Add(-, "te"); ht.Add(-, "teng");
ht.Add(-, "ti"); ht.Add(-, "tian"); ht.Add(-, "tiao");
ht.Add(-, "tie"); ht.Add(-, "ting"); ht.Add(-, "tong");
ht.Add(-, "tou"); ht.Add(-, "tu"); ht.Add(-, "tuan");
ht.Add(-, "tui"); ht.Add(-, "tun"); ht.Add(-, "tuo");
ht.Add(-, "wa"); ht.Add(-, "wai"); ht.Add(-, "wan");
ht.Add(-, "wang"); ht.Add(-, "wei"); ht.Add(-, "wen");
ht.Add(-, "weng"); ht.Add(-, "wo"); ht.Add(-, "wu");
ht.Add(-, "xi"); ht.Add(-, "xia"); ht.Add(-, "xian");
ht.Add(-, "xiang"); ht.Add(-, "xiao"); ht.Add(-, "xie");
ht.Add(-, "xin"); ht.Add(-, "xing"); ht.Add(-, "xiong");
ht.Add(-, "xiu"); ht.Add(-, "xu"); ht.Add(-, "xuan");
ht.Add(-, "xue"); ht.Add(-, "xun"); ht.Add(-, "ya");
ht.Add(-, "yan"); ht.Add(-, "yang"); ht.Add(-, "yao");
ht.Add(-, "ye"); ht.Add(-, "yi"); ht.Add(-, "yin");
ht.Add(-, "ying"); ht.Add(-, "yo"); ht.Add(-, "yong");
ht.Add(-, "you"); ht.Add(-, "yu"); ht.Add(-, "yuan");
ht.Add(-, "yue"); ht.Add(-, "yun"); ht.Add(-, "za");
ht.Add(-, "zai"); ht.Add(-, "zan"); ht.Add(-, "zang");
ht.Add(-, "zao"); ht.Add(-, "ze"); ht.Add(-, "zei");
ht.Add(-, "zen"); ht.Add(-, "zeng"); ht.Add(-, "zha");
ht.Add(-, "zhai"); ht.Add(-, "zhan"); ht.Add(-, "zhang");
ht.Add(-, "zhao"); ht.Add(-, "zhe"); ht.Add(-, "zhen");
ht.Add(-, "zheng"); ht.Add(-, "zhi"); ht.Add(-, "zhong");
ht.Add(-, "zhou"); ht.Add(-, "zhu"); ht.Add(-, "zhua");
ht.Add(-, "zhuai"); ht.Add(-, "zhuan"); ht.Add(-, "zhuang");
ht.Add(-, "zhui"); ht.Add(-, "zhun"); ht.Add(-, "zhuo");
ht.Add(-, "zi"); ht.Add(-, "zong"); ht.Add(-, "zou");
ht.Add(-, "zu"); ht.Add(-, "zuan"); ht.Add(-, "zui");
ht.Add(-, "zun"); ht.Add(-, "zuo"); ht.Add(-, "zz");ht.Add(-9254,"zhen")
return ht;
} static void Main(string[] args)
{
var result = GetSpell("张三");
Console.WriteLine(result);
Console.ReadKey();
}
}

c#获取文字全拼音的更多相关文章
- JS实现获取汉字首字母拼音、全拼音及混拼音的方法
本文实例讲述了JS实现获取汉字首字母拼音.全拼音及混拼音的方法.分享给大家供大家参考,具体如下: 这里需要用到一个js获取汉字拼音的插件,可点击此处本站下载. 运行效果如下: 完整示例代码: ? 1 ...
- C# 获取汉字的拼音首字母和全拼(含源码)
C# 获取汉字的拼音首字母 一种是把所有中文字符集合起来组成一个对照表:另一种是依照汉字在Unicode编码表中的排序来确定拼音的首字母.碰到多音字时就以常用的为准(第一种方法中可以自行更改,方法为手 ...
- php获取汉字的拼音 拼音首字母
/***获取汉字的拼音*/function pinyin($s, $isfirst = false) { static $pinyins; $s = trim($s); $len = strlen($ ...
- C#获取字符串的拼音和首字母
在C#中我们想要获取字符串的拼音并不是那么困难的,在网上看到很多都是特别笨的方式来实现,其实各有各的好处吧,如果使用了下方法方式,它不知道多音字,这就是一个问题. /// <summary> ...
- javaScript对文字按照拼音排序
<title>JavaScript对文字按照拼音排序</title> <SCRIPT type="text/javascript"> funct ...
- php 获取中文字符拼音首字母
//php获取中文字符拼音首字母 function getFirstCharter($str){ if(empty($str)){return '';} $fchar=ord($str{}); }); ...
- php 获取中文的拼音
注意事项: 无法识别的中文 亳:bo,如果有此字,结果为空,调用此类之前需要手动加判断 蚌:bang,beng,多音字 莞:guan 圳:zhen 儋:dan 漯:luo 濮:pu 泸:lu 衢:qu ...
- iOS获取汉字的拼音
在iOS开发中经常涉及到汉字的排序,最常见的就是需要根据首字母的字符顺序排列,比如常见的通讯录等.总结出来,大致可以分为两种方法,其中参考文献[1]中提供的方法十分复杂,利用查表的方法是先,并且代码量 ...
- (转载)delphi中获取汉字的拼音首字母
delphi中获取汉字的拼音首字母1.py: array[216..247] of string = ({216}'CJWGNSPGCGNESYPB' + 'TYYZDXYKYGTDJNMJ' + ' ...
随机推荐
- 【POJ 1958】 Strange Towers of Hanoi
[题目链接] http://poj.org/problem?id=1958 [算法] 先考虑三个塔的情况,g[i]表示在三塔情况下的移动步数,则g[i] = g[i-1] * 2 + 1 再考虑四个塔 ...
- eclipse和jdk版本对应问题
日常开发中,32位eclipse要用32位jdk,64位则必须要用64位jdk,否则启动时就会报错,load jvm.dll失败,昨天又遇到了这个问题.更换对应的版本之后就好了.tomcat等应用也有 ...
- 洛谷 P3377 模板左偏树
题目:https://www.luogu.org/problemnew/show/P3377 左偏树的模板题: 加深了我对空 merge 的理解: 结构体的编号就是原序列的位置. 代码如下: #inc ...
- Spark 机器学习 ---CountVectorizer
文本特征提取->> CountVectorizer:基于词频数的文档向量 package Spark_MLlib import org.apache.spark.ml.feature.Co ...
- Django-CKeditor使用笔记
1. 安装django-ckeditor $ pip install django-ckeditor 2. 在setting中,添加ckeditor , ckeditor_uploader 到INST ...
- Mechanize抓取数据【Ruby】
创建: 2017/08/05 更新: 2018/01/08 修正: ele_inner_text -> ele.inner_text 补充: ...
- [Apple开发者帐户帮助]九、参考(2)撤销特权
您可以撤消的证书取决于证书类型和您的角色.如果您是个人注册,则可以撤销所有类型的开发和分发证书,除非另有说明.组织团队的任何成员都可以撤销自己的开发证书,但只有帐户持有人或管理员可以撤销分发证书. 证 ...
- Cause: org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'empid' in 'class cn.happy.entity.Emp'
org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.apache.i ...
- sql server 无法创建数据库,错误代码:1807
SQL Server 不能创建数据库,发生错误:1807 :未能获得数据库 'model' 上的排它锁.请稍后重试操作. declare @sql varchar(100) while ...
- Moto P30(XT1943-1) 免解锁BL 免rec 保留数据 Magisk Xposed ROOT 救砖 ZUI 4.0.374
>>>重点介绍<<< 第一:本刷机包可卡刷可线刷,刷机包比较大的原因是采用同时兼容卡刷和线刷的格式,所以比较大第二:[卡刷方法]卡刷不要解压刷机包,直接传入手机后用 ...