C#计算汉语拼音
2005-07-27 14:57
351 查看
static public string GetChineseSpell(string strText)
{
int len = strText.Length;
string myStr = "";
for(int i=0;i<len;i++)
{
myStr += getSpell(strText.Substring(i,1));
}
return myStr;
}
static public string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
if(arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area<<8) + pos;
int[] areacode = {45217,45253,45761,46318,46826,47010,47297,47614,48119,48119,49062,49324,49896,50371,50614,50622,50906,51387,51446,52218,52698,52698,52698,52980,53689,54481};
for(int i=0;i<26;i++)
{
int max = 55290;
if(i != 25) max = areacode[i+1];
if(areacode[i]<=code && code<max)
{
return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
}
}
return "*";
}
else return cnChar;
}
{
int len = strText.Length;
string myStr = "";
for(int i=0;i<len;i++)
{
myStr += getSpell(strText.Substring(i,1));
}
return myStr;
}
static public string getSpell(string cnChar)
{
byte[] arrCN = Encoding.Default.GetBytes(cnChar);
if(arrCN.Length > 1)
{
int area = (short)arrCN[0];
int pos = (short)arrCN[1];
int code = (area<<8) + pos;
int[] areacode = {45217,45253,45761,46318,46826,47010,47297,47614,48119,48119,49062,49324,49896,50371,50614,50622,50906,51387,51446,52218,52698,52698,52698,52980,53689,54481};
for(int i=0;i<26;i++)
{
int max = 55290;
if(i != 25) max = areacode[i+1];
if(areacode[i]<=code && code<max)
{
return Encoding.Default.GetString(new byte[]{(byte)(65+i)});
}
}
return "*";
}
else return cnChar;
}
相关文章推荐
- c#计算汉语拼音码
- C#中使用TimeSpan计算两个时间的差值
- C#第2次试验(1).创建一个抽象类A,该类中包含一个求两个数之和抽象方法。创建一个子类B,在B中重写求和方法,且使用方法重载使得方法可以分别计算整数、双精度、字符串。
- AMP(Gpu并行计算,c#,vc++11) 学习(一)
- c# 计算星座
- C#计算两点间的距离
- c# 奖金计算
- C#实现的根据年月日计算星期几的函数
- C#计算时间差
- 一个简单方法完成C#时间间隔的计算
- VS2010(c#)-实现数字计算器
- 计算复利率小程序(C#版)
- C# / ASP.NET 计算某个日期所在的周是当年的第几周
- c# 自动计算字符串的宽度
- C#时间计算DateTime
- C# 计算一段代码执行的时间函数
- c#在字符串中计算加减乘除...
- [转载]C#计算程序执行时间
- C#计算日期之间的差值
- C# 计算MD5值