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 ...
随机推荐
- Java基础 println 输出常量的示例
JDK :OpenJDK-11 OS :CentOS 7.6.1810 IDE :Eclipse 2019‑03 typesetting :Markdown code ...
- Leetcode: Minimum Domino Rotations For Equal Row
In a row of dominoes, A[i] and B[i] represent the top and bottom halves of the i-th domino. (A domin ...
- Dart匿名方法函数和闭包
/* 内置方法/函数: print(); 自定义方法: 自定义方法的基本格式: 返回类型 方法名称(参数1,参数2,...){ 方法体 return 返回值; } */ void printInfo( ...
- CDH 部署 Hadoop:5.开始安装
Cloudera Enterprise 6.2.x 或者参考https://blog.csdn.net/shawnhu007/article/details/52579204 第零步:优化相关 e ...
- gfs下载文件较大,可以分区域分变量下载
一.下载 所有字段的GFS预报(大致有325个字段),1度的文件有1G多,0.5度的3.5G左右. 若每天下载0.6.12.18四个发布点的数据,那是很费时费力的.而且经常会被IDS/IPS设备 ...
- QTableView加载数据
void VCAdmin::searchAllUser() { strID_Index = ""; if (NULL == vcManageDatabaseObj) { vc_ad ...
- Spring cloud微服务安全实战-3-7API安全机制之数据加密
这一节来聊一下密码的加密. 加密盐,为了避免两个相同的面加密出来的密文是一样的,每个人的盐不一样, 首先引入工具包,lambdaworks <!-- https://mvnrepository. ...
- 【JS】jquery展示JSON插件JSONView
JSONView介绍 jQuery插件,用于显示漂亮的JSON. 官网地址:https://plugins.jquery.com/jsonview/ git地址:https://github.com/ ...
- C++构造函数以及何时被调用
using namespace std; class A { public: A() { cout << "默认无参构造函数" << endl; } #if ...
- UCloud云盘系统安装