C#汉字转换成全拼的拼音
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions; namespace WL.Common
{
/// 汉字转拼音类
public class EcanConvertToCh
{
//定义拼音区编码数组
private static int[] getValue = new int[]
{
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-, -,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-,
-,-,-,-,-,-,-,-,-,-,-,-
};
//定义拼音数组
private static string[] getName = new string[]
{
"A","Ai","An","Ang","Ao","Ba","Bai","Ban","Bang","Bao","Bei","Ben",
"Beng","Bi","Bian","Biao","Bie","Bin","Bing","Bo","Bu","Ba","Cai","Can",
"Cang","Cao","Ce","Ceng","Cha","Chai","Chan","Chang","Chao","Che","Chen","Cheng",
"Chi","Chong","Chou","Chu","Chuai","Chuan","Chuang","Chui","Chun","Chuo","Ci","Cong",
"Cou","Cu","Cuan","Cui","Cun","Cuo","Da","Dai","Dan","Dang","Dao","De",
"Deng","Di","Dian","Diao","Die","Ding","Diu","Dong","Dou","Du","Duan","Dui",
"Dun","Duo","E","En","Er","Fa","Fan","Fang","Fei","Fen","Feng","Fo",
"Fou","Fu","Ga","Gai","Gan","Gang","Gao","Ge","Gei","Gen","Geng","Gong",
"Gou","Gu","Gua","Guai","Guan","Guang","Gui","Gun","Guo","Ha","Hai","Han",
"Hang","Hao","He","Hei","Hen","Heng","Hong","Hou","Hu","Hua","Huai","Huan",
"Huang","Hui","Hun","Huo","Ji","Jia","Jian","Jiang","Jiao","Jie","Jin","Jing",
"Jiong","Jiu","Ju","Juan","Jue","Jun","Ka","Kai","Kan","Kang","Kao","Ke",
"Ken","Keng","Kong","Kou","Ku","Kua","Kuai","Kuan","Kuang","Kui","Kun","Kuo",
"La","Lai","Lan","Lang","Lao","Le","Lei","Leng","Li","Lia","Lian","Liang",
"Liao","Lie","Lin","Ling","Liu","Long","Lou","Lu","Lv","Luan","Lue","Lun",
"Luo","Ma","Mai","Man","Mang","Mao","Me","Mei","Men","Meng","Mi","Mian",
"Miao","Mie","Min","Ming","Miu","Mo","Mou","Mu","Na","Nai","Nan","Nang",
"Nao","Ne","Nei","Nen","Neng","Ni","Nian","Niang","Niao","Nie","Nin","Ning",
"Niu","Nong","Nu","Nv","Nuan","Nue","Nuo","O","Ou","Pa","Pai","Pan",
"Pang","Pao","Pei","Pen","Peng","Pi","Pian","Piao","Pie","Pin","Ping","Po",
"Pu","Qi","Qia","Qian","Qiang","Qiao","Qie","Qin","Qing","Qiong","Qiu","Qu",
"Quan","Que","Qun","Ran","Rang","Rao","Re","Ren","Reng","Ri","Rong","Rou",
"Ru","Ruan","Rui","Run","Ruo","Sa","Sai","San","Sang","Sao","Se","Sen",
"Seng","Sha","Shai","Shan","Shang","Shao","She","Shen","Sheng","Shi","Shou","Shu",
"Shua","Shuai","Shuan","Shuang","Shui","Shun","Shuo","Si","Song","Sou","Su","Suan",
"Sui","Sun","Suo","Ta","Tai","Tan","Tang","Tao","Te","Teng","Ti","Tian",
"Tiao","Tie","Ting","Tong","Tou","Tu","Tuan","Tui","Tun","Tuo","Wa","Wai",
"Wan","Wang","Wei","Wen","Weng","Wo","Wu","Xi","Xia","Xian","Xiang","Xiao",
"Xie","Xin","Xing","Xiong","Xiu","Xu","Xuan","Xue","Xun","Ya","Yan","Yang",
"Yao","Ye","Yi","Yin","Ying","Yo","Yong","You","Yu","Yuan","Yue","Yun",
"Za", "Zai","Zan","Zang","Zao","Ze","Zei","Zen","Zeng","Zha","Zhai","Zhan",
"Zhang","Zhao","Zhe","Zhen","Zheng","Zhi","Zhong","Zhou","Zhu","Zhua","Zhuai","Zhuan",
"Zhuang","Zhui","Zhun","Zhuo","Zi","Zong","Zou","Zu","Zuan","Zui","Zun","Zuo"
};
/// <summary>汉字转换成全拼的拼音</summary>
/// <param name="Chstr">汉字字符串</param>
/// <returns>转换后的拼音字符串</returns>
public static string convertCh(string Chstr)
{
Regex reg = new Regex("^[\u4e00-\u9fa5]$");//验证是否输入汉字
byte[] arr = new byte[];
string pystr = "";
int asc = , M1 = , M2 = ;
char[] mChar = Chstr.ToCharArray();//获取汉字对应的字符数组
for (int j = ; j < mChar.Length; j++)
{
//如果输入的是汉字
if (reg.IsMatch(mChar[j].ToString()))
{
arr = System.Text.Encoding.Default.GetBytes(mChar[j].ToString());
M1 = (short)(arr[]);
M2 = (short)(arr[]);
asc = M1 * + M2 - ;
if (asc > && asc < )
{
pystr += mChar[j];
}
else
{
switch (asc)
{
case -:
pystr += "Zhen"; break;
case -:
pystr += "Qian"; break;
case -:
pystr += "Jia"; break;
case -:
pystr += "Ge"; break;
case -:
pystr += "Ga"; break;
case -:
pystr += "La"; break;
case -:
pystr += "Chen"; break;
case -:
pystr += "Mao"; break;
case -:
pystr += "Mao"; break;
case -:
pystr += "Die"; break;
case -:
pystr += "Tian"; break;
default:
for (int i = (getValue.Length - ); i >= ; i--)
{
if (getValue[i] <= asc) //判断汉字的拼音区编码是否在指定范围内
{
pystr += getName[i];//如果不超出范围则获取对应的拼音
break;
}
}
break;
}
}
}
else//如果不是汉字
{
pystr += mChar[j].ToString();//如果不是汉字则返回
}
}
return pystr;//返回获取到的汉字拼音
}
}
}
C#汉字转换成全拼的拼音的更多相关文章
- C#将汉字转换成全拼的拼音EcanConvertToCh帮助类 (转)
点击下载 EcanConvertToCh.rar 主要功能就是将汉字转换成全拼的拼音,只要你输入一个汉字就会相应的转成拼音 /// <summary> /// 编 码 人:苏飞 /// 联 ...
- Mysql中文汉字转拼音的实现(每个汉字转换全拼)
-- 创建汉字拼音对照临时表 CREATE TABLE IF NOT EXISTS `t_base_pinyin` ( `pin_yin_` varchar(255) CHARACTER SET gb ...
- 通过pinyin4j将汉字转换为全拼 和 拼音首字母
/** * 汉字转换为拼音 包含多音字,包含生母zh,ch,sh的 */ public void toPinYinAll(){ String initials = "zh,ch,sh&quo ...
- c#把汉字转化成全拼音函数(全拼)
/// <summary> /// 把汉字转换成拼音(全拼) /// </summary> /// <param name=&q ...
- C++ 将汉字转换成拼音全拼
#include <string> using std::string; //======================================================= ...
- C++ 将汉字转换成拼音全拼【转载】
转载自https://www.cnblogs.com/mzhrd/p/4758105.html #include <string> using std::string; //======= ...
- SQL 汉字转换成拼音首字母 首字母查
-- ============================================= -- 功能:汉字转换成拼音首字母 首字母查 -- ========================== ...
- C#汉字转换拼音技术详解
C#汉字转换拼音技术详解(高性能) 下面将源代码贴出.public static class ChineseToPinYin { private sta ...
- python把汉字转换成拼音实现程序
python把汉字转换成拼音实现程序 文章一个简洁干的汉字转拼音 程序,复制下载就可以直接使用,有需要的同学可以参考一下下. #coding:utf-8 #基于python2.6 table = 'a ...
随机推荐
- 替换分隔符 ^p, 或者是回车
1 Excel 里面的数据, 粘出来到notepad上,再从notepad 粘到word, 再把world里面的分隔符或者是回车符替换成 其他的 .
- 原理分析dubbo分布式应用中使用zipkin做链路追踪(转)
作者:@nele本文为作者原创,转载请注明出处:https://www.cnblogs.com/nele/p/10171794.html 目录 zipkin是什么为什么使用Zipkinzipkin架构 ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第三节SpringBoot热部署devtool和配置文件自动注入实战_14、SpringBoot2.x使用Dev-tool热部署
学习笔记 热部署 每次修改了代码都需要关闭应用重启 热部署就是有一个插件会监听我们应用的代码文件是否有变化,如果有变化就会有其他的类加载器加载 主要的依赖 复制到我们的pom.xml里面 安装完成ja ...
- 获取并打印Spring容器中所有的Bean名称
思路: 1.实现Spring的ApplicationContextAware接口,重写setApplicationContext方法,将得到的ApplicationContext对象保存到一个静态变量 ...
- ISO/IEC 9899:2011 条款6.8.4——选择语句
6.8.4 选择语句 语法 1.selection-statement: if ( expression ) statement if ( expression ...
- php cURL error 60: SSL certificate problem: unable to get local issuer certificate 解决办法
错误例子如下: php5.6以上的版本会出现这种问题 关于“SSL证书问题:无法获取本地颁发者证书”错误.很明显,这适用于发送CURL请求的系统(并且没有服务器接收请求) 1)从https://cur ...
- Django架站的16堂課
Django架站的16堂課-活用Django+Web+Framework快速构建移动网站 目录 第1堂 网站开发环境的建立 1 1.1 网站的基础知识 1 1.1.1 网站的运行流程 1 1.1.2 ...
- 【翻译】The Broadcast State Pattern(广播状态)
本文翻译自官网:The Broadcast State Pattern Provided APIs (提供的api) BroadcastProcessFunction and KeyedBroadca ...
- Swift4.0复习循环
1.for-in循环: 2.while循环: 3.repeat-while循环: repeat { // 循环体中的一条或多条执行语句 } while condition 4.标签语句: if_lab ...
- npm 全局安装路径 在哪里
注意:在Admin下,需要把隐藏文件显示出来,才能找到对应的文件路径.