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' + ' ...
随机推荐
- touch事件的分发机制
作者:谢昆 一段伪代码反应整个touch事件的分发 public boolean dispatchTouchEvent(MotionEvent event) { boolean consume = f ...
- java线程异常处理方法
工作中常发现有些程序发生异常但却没有错误日志,原因就是一些开发线程异常处理错误,导致程序报错但异常信息打印到堆栈上,不好在生产环境中定位问题. 在java多线程程序中,所有线程都不允许抛出未捕获的ch ...
- 【转载】HashMap实现原理浅析
HashMap和Hashtable的区别 两者最主要的区别在于Hashtable是线程安全,而HashMap则非线程安全Hashtable的实现方法里面都添加了synchronized关键字来确保线程 ...
- Java的安装过程
记录一下自己在Windowns下安装java的过程 安装网址:http://www.oracle.com/index.html 打开网址后要先登录,如果没有号就先注册,然后才能下载 step1:下载J ...
- Python机器学习算法 — K-Means聚类
K-Means简介 步,直到每个簇的中心基本不再变化: 6)将结果输出. K-Means的说明 如图所示,数据样本用圆点表示,每个簇的中心点用叉叉表示: (a)刚开始时是原始数据,杂乱无章 ...
- [Swift通天遁地]四、网络和线程-(11)将服务器返回的JSON映射为实例对象
★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...
- VB.NET学习体会
注:本文写于2018年01月28日,首先发表于CSDN博客"aopstudio的博客"上 下学期要学习VB.NET程序设计课程,这几天在家开始自习.在自习的过程中发现VB.NET和 ...
- .Net Core开源小工具mssql2mysql,从mssql生成mysql脚本
Microsoft SQL Server to MySQL 这个工具用于从MSSQL生成MySQL脚本,生成的脚本包含表结构和数据 安装 这是一个.Net Core的具具,所以需要先安装.net co ...
- Django基于JWT实现微信小程序的登录和鉴权
什么是JWT? JWT,全称Json Web Token,用于作为JSON对象在各方之间安全地传输信息.该信息可以被验证和信任,因为它是数字签名的. 与Session的区别 一.Session是在服务 ...
- promise 小抄
catch的用法 我们知道Promise对象除了then方法,还有一个catch方法,它是做什么用的呢?其实它和then的第二个参数一样,用来指定reject的回调,用法是这样: getNumber( ...