C#实现汉字转换为拼音缩写的代码
作者:2778085001 时间:2021-11-21 04:04:51
本文实例为大家分享了C#汉字转换为拼音缩写的实现代码,供大家参考,具体内容如下
using System;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Write(GetPYString("中华人民共和国"));
}
public string GetPYString(string str)
{
string tempStr = "";
foreach (char c in str)
{
if ((int)c >= 33 && (int)c <= 126)
{//字母和符号原样保留
tempStr += c.ToString();
}
else
{//累加拼音声母
tempStr += GetPYChar(c.ToString());
}
}
return tempStr;
}
///
/// 取单个字符的拼音声母
///
/// 要转换的单个汉字
/// 拼音声母
public string GetPYChar(string c)
{
byte[] array = new byte[2];
array = System.Text.Encoding.Default.GetBytes(c);
int i = (short)(array[0] - '\0') * 256 + ((short)(array[1] - '\0'));
if (i < 0xB0A1) return "*";
if (i < 0xB0C5) return "a";
if (i < 0xB2C1) return "b";
if (i < 0xB4EE) return "c";
if (i < 0xB6EA) return "d";
if (i < 0xB7A2) return "e";
if (i < 0xB8C1) return "f";
if (i < 0xB9FE) return "g";
if (i < 0xBBF7) return "h";
if (i < 0xBFA6) return "g";
if (i < 0xC0AC) return "k";
if (i < 0xC2E8) return "l";
if (i < 0xC4C3) return "m";
if (i < 0xC5B6) return "n";
if (i < 0xC5BE) return "o";
if (i < 0xC6DA) return "p";
if (i < 0xC8BB) return "q";
if (i < 0xC8F6) return "r";
if (i < 0xCBFA) return "s";
if (i < 0xCDDA) return "t";
if (i < 0xCEF4) return "w";
if (i < 0xD1B9) return "x";
if (i < 0xD4D1) return "y";
if (i < 0xD7FA) return "z";
return "*";
}
}
标签:C#,拼音
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
字符串内存驻留机制详解示例
2023-09-24 04:09:32
Spring Boot2.x如何自定义Endpoint
2023-03-05 18:04:12
intellij idea使用git stash暂存一次提交的操作
2023-03-08 08:30:11
![](https://img.aspxhome.com/file/2023/5/63435_0s.jpg)
Java金额大小写的转换方法
2023-08-23 00:26:11
Java中SpringSecurity密码错误5次锁定用户的实现方法
2021-07-10 10:38:17
Java实现的微信公众号获取微信用户信息示例
2022-04-25 15:15:29
深入剖析构建JSON字符串的三种方式(推荐)
2023-09-26 07:47:22
![](https://img.aspxhome.com/file/2023/6/68696_0s.png)
在AOP中Spring生成代理类的两种方式
2023-12-08 19:13:36
带你详细了解Java值传递和引用传递
2023-02-19 08:42:26
![](https://img.aspxhome.com/file/2023/9/61009_0s.jpg)
spring boot 打包jar jar没有主目录清单问题的完美解决方法
2021-08-28 16:07:39
![](https://img.aspxhome.com/file/2023/9/65149_0s.png)
浅谈Java中方法参数传递的问题
2021-11-06 04:24:46
![](https://img.aspxhome.com/file/2023/4/60034_0s.png)
常见的排序算法,一篇就够了
2022-06-16 06:56:34
![](https://img.aspxhome.com/file/2023/4/70544_0s.jpg)
Spring Boot 实现图片上传并回显功能
2021-10-11 17:45:20
![](https://img.aspxhome.com/file/2023/6/68776_0s.png)
Java如何定义Long类型
2022-05-28 22:28:52
![](https://img.aspxhome.com/file/2023/6/62246_0s.png)
如何使用Jenkins构建GIT+Maven项目
2021-11-18 04:42:52
![](https://img.aspxhome.com/file/2023/9/61839_0s.png)
IDEA+maven+SpringBoot+JPA+Thymeleaf实现Crud及分页
2023-04-14 18:33:46
![](https://img.aspxhome.com/file/2023/7/71157_0s.jpg)
java自定义ClassLoader加载指定的class文件操作
2022-03-16 16:19:07
![](https://img.aspxhome.com/file/2023/8/60848_0s.jpg)
浅析Disruptor高性能线程消息传递并发框架
2023-02-26 14:09:01
![](https://img.aspxhome.com/file/2023/8/74988_0s.png)
C# 修改文件的创建、修改和访问时间的示例
2023-06-09 23:18:50
SpringBoot启动yaml报错的解决
2021-09-09 22:58:14
![](https://img.aspxhome.com/file/2023/9/69089_0s.png)