C#汉字转拼音
下面这个方法里 ' _Allhz' 是在什么地方声明的?
还有一个地方报错,因为给删了,想不起来了;
大家有用过这个方法的?
public static string ConvertPY(string SourceString)
{
if (SourceString == null)
return null;
Encoding ed = Encoding.GetEncoding("GB2312");
if (ed == null)
throw (new ArgumentException("没有找到编码集GB2312"));
int bh = 0;
char[] charary = SourceString.ToCharArray();
byte[] bAry = new byte[2];
StringBuilder rtnSb = new StringBuilder();
for (int i = 0; i < charary.Length; i++)
{
bAry = ed.GetBytes(charary[i].ToString());
if (bAry.Length == 1)
{
rtnSb.Append(charary[i]);
continue;
}
bh = bAry[0] - 0xA0;
if (0x10 <= bh && bh <= 0x57) //是gb2312汉字
{
bool isFind = false;
for (int j = 0; j < _Allhz.Length; j++)
{
if (_Allhz[j][1].IndexOf(charary[i]) != -1)
{
rtnSb.Append(_Allhz[j][0]);
isFind = true;
break;
}
}
if (!isFind)
rtnSb.Append(charary[i]);
}
else
rtnSb.Append(charary[i]);
}
return rtnSb.ToString();
}
还有一个地方报错,因为给删了,想不起来了;
大家有用过这个方法的?
public static string ConvertPY(string SourceString)
{
if (SourceString == null)
return null;
Encoding ed = Encoding.GetEncoding("GB2312");
if (ed == null)
throw (new ArgumentException("没有找到编码集GB2312"));
int bh = 0;
char[] charary = SourceString.ToCharArray();
byte[] bAry = new byte[2];
StringBuilder rtnSb = new StringBuilder();
for (int i = 0; i < charary.Length; i++)
{
bAry = ed.GetBytes(charary[i].ToString());
if (bAry.Length == 1)
{
rtnSb.Append(charary[i]);
continue;
}
bh = bAry[0] - 0xA0;
if (0x10 <= bh && bh <= 0x57) //是gb2312汉字
{
bool isFind = false;
for (int j = 0; j < _Allhz.Length; j++)
{
if (_Allhz[j][1].IndexOf(charary[i]) != -1)
{
rtnSb.Append(_Allhz[j][0]);
isFind = true;
break;
}
}
if (!isFind)
rtnSb.Append(charary[i]);
}
else
rtnSb.Append(charary[i]);
}
return rtnSb.ToString();
}
...全文
相关推荐
C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母
C#汉字转拼音(npinyin)将中文转换成拼音全文或首字母
C#实现汉字转拼音完整教程及源码
本文还有配套的精品资源,点击获取 简介:在编程领域,将汉字转换为拼音是文本处理的重要环节,尤其是在搜索引擎优化和关键词提取等应用场景。C#作为面向对象的编程语言,借助.NET框架的强大支持,可以实现汉字到拼音的转换功能。本文介绍了.NET Framework中的TextInfo类和第三方库如Pinyin4Net在汉字转拼音中的应用,以及自行编写的算法实现步骤。此外,还探讨了...
C# unity汉字转拼音.zip
C#汉字转拼音的dll库文件,直接下载使用,配合这个教程,简单易学,易用,大家一起学习,一起进步。 C#汉字转拼音的dll库文件,直接下载使用,配合这个教程,简单易学,易用,大家一起学习,一起进步。
c#汉字转拼音
c#汉字转拼音,共有两个类,实现常用得汉字向拼音得转换
C# 汉字转拼音
汉字转拼音 或 转拼音首字母 大写 Vs2010



