C#获取汉字的拼音的首拼
2008-07-08 09:44
239 查看
public string getSpell(string cn)
{
string tempChar = "";
char[] temp = cn.ToCharArray();
for (int j = 0; j < temp.Length; j++)
{
byte[] arrCN = Encoding.Default.GetBytes(temp[j].ToString());
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)
{
tempChar+= Encoding.Default.GetString(new byte[] { (byte)(65 + i) }).ToLower();
}
}
//tempChar += "?";
}
else
tempChar += cn;
}
return tempChar;
}
{
string tempChar = "";
char[] temp = cn.ToCharArray();
for (int j = 0; j < temp.Length; j++)
{
byte[] arrCN = Encoding.Default.GetBytes(temp[j].ToString());
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)
{
tempChar+= Encoding.Default.GetString(new byte[] { (byte)(65 + i) }).ToLower();
}
}
//tempChar += "?";
}
else
tempChar += cn;
}
return tempChar;
}
相关文章推荐
- C#_获取汉字拼音
- C# 获取汉字拼音首字母
- C# 获取汉字拼音首字母
- 使用C#获取汉字的拼音首字母
- C#获取汉字拼音
- C#获取汉字字符串拼音首字母的方法
- C# 获取汉字拼音
- C#中如何获取汉字的笔画数和汉字的拼音
- C# winform 获取汉字首字母拼音
- 怎样获取一组汉字的拼音首字母(使用C#)
- c# asp.net 2.0 获取汉字第一个拼音
- c# 根据中文汉字获取到拼音
- C#获取包括一二级汉字的拼音首字母方法
- C# 获取汉字的拼音首字母
- C# 获取汉字拼音首字母(修正)
- C#获取汉字拼音
- C#中实现输入汉字获取其拼音(汉字转拼音)的2种方法
- C# 获取汉字的拼音首字母(转)
- C#使用微软语言包来获取中文汉字的拼音、拼音首字母、中文繁体
- C# 获取汉字拼音首字母(修正)