如何得到一个中文文字所对应的拼音??? 输入一个文字或单词,如何显示其拼音或对应的键盘字母组合?? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /// <summary>/// 返回指定字符串的汉语拼音首字母/// </summary>/// <param name="strText"></param>/// <returns></returns>public static string GetChineseSpell(string strText){ if (Empty.IsEmpty(strText)) return ""; int len = strText.Length; string myStr = ""; for (int i = 0; i < len; i++) { myStr += getSpell(strText.Substring(i, 1)); } return myStr;}private static string getSpell(string cnChar){ byte[] arrCN = System.Text.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 System.Text.Encoding.Default.GetString(new byte[] { (byte)(65 + i) }); } } return "*"; } else return cnChar;} 网上找的using system; using system.drawing; using system.collections; using system.componentmodel; using system.windows.forms; using system.data; namespace winet { /// <summary> /// classfun 的摘要说明。 /// </summary> public class classfun { private string capstr; public classfun() { // // todo: 在此处添加构造函数逻辑 // } public string chinesecap(string chinesestr) { byte[] zw = new byte[2]; long chinesestr_int; string charstr,chinastr=""; for (int i=0;i<=chinesestr.length-1;i++) { charstr=chinesestr.substring(i,1).tostring(); zw=system.text.encoding.default.getbytes(charstr); // 得到汉字符的字节数组 if(zw.length==2) { int i1 = (short)(zw[0]); int i2 = (short)(zw[1]); chinesestr_int=i1*256+i2; //table of the constant list // a; //45217..45252 // b; //45253..45760 // c; //45761..46317 // d; //46318..46825 // e; //46826..47009 // f; //47010..47296 // g; //47297..47613 // h; //47614..48118 // j; //48119..49061 // k; //49062..49323 // l; //49324..49895 // m; //49896..50370 // n; //50371..50613 // o; //50614..50621 // p; //50622..50905 // q; //50906..51386 // r; //51387..51445 // s; //51446..52217 // t; //52218..52697 //没有u,v // w; //52698..52979 // x; //52980..53640 // y; //53689..54480 // z; //54481..55289 if ((chinesestr_int>=45217) && (chinesestr_int<=45252)) { chinastr= "a"; } else if ((chinesestr_int>=45253) && (chinesestr_int<=45760)) { chinastr= "b"; } else if ((chinesestr_int>=45761) && (chinesestr_int<=46317)) { chinastr= "c"; } else if ((chinesestr_int>=46318) && (chinesestr_int<=46825)) { chinastr= "d"; } else if ((chinesestr_int>=46826) && (chinesestr_int<=47009)) { chinastr= "e"; } else if ((chinesestr_int>=47010) && (chinesestr_int<=47296)) { chinastr= "f"; } else if ((chinesestr_int>=47297) && (chinesestr_int<=47613)) { chinastr= "g"; } else if ((chinesestr_int>=47614) && (chinesestr_int<=48118)) { chinastr= "h"; } else if ((chinesestr_int>=48119) && (chinesestr_int<=49061)) { chinastr= "j"; } else if ((chinesestr_int>=49062) && (chinesestr_int<=49323)) { chinastr= "k"; } else if ((chinesestr_int>=49324) && (chinesestr_int<=49895)) { chinastr= "l"; } else if ((chinesestr_int>=49896) && (chinesestr_int<=50370)) { chinastr= "m"; } else if ((chinesestr_int>=50371) && (chinesestr_int<=50613)) { chinastr= "n"; } else if ((chinesestr_int>=50614) && (chinesestr_int<=50621)) { chinastr= "o"; } else if ((chinesestr_int>=50622) && (chinesestr_int<=50905)) { chinastr= "p"; } else if ((chinesestr_int>=50906) && (chinesestr_int<=51386)) { chinastr= "q"; } else if ((chinesestr_int>=51387) && (chinesestr_int<=51445)) { chinastr= "r"; } else if ((chinesestr_int>=51446) && (chinesestr_int<=52217)) { chinastr= "s"; } else if ((chinesestr_int>=52218) && (chinesestr_int<=52697)) { chinastr= "t"; } else if ((chinesestr_int>=52698) && (chinesestr_int<=52979)) { chinastr= "w"; } else if ((chinesestr_int>=52980) && (chinesestr_int<=53640)) { chinastr= "x"; } else if ((chinesestr_int>=53689) && (chinesestr_int<=54480)) { chinastr= "y"; } else if ((chinesestr_int>=54481) && (chinesestr_int<=55289)) { chinastr= "z"; } } else { capstr=chinesestr; break; } capstr=capstr+chinastr; } return capstr; } } } 以前网上找到过一个。基本上是做一个字典。通过字库对应查找。google一下。 传段文字,与各位无关 安装部署项目如何增加配置文件? sql 服务器 占用CPU 100% 大家帮我看看我的WP7 程序怎么回事 怎么运行不了 如何去掉vs 2005 中DataGridView末尾的空行? listview鼠标可以滚动,但不出现滚动条 是采用Web Service还是用Remoting? mm马上给分重酬!水晶报表交叉表如何隐藏汇总字段? 简单问题送粉了 在DataSet找到满足条件的记录进行更新。或删除。 javascript和this.SmartNavigation=true冲突?怎么解决呢? 小规模交流一下——大家现在用的 VS 是什么版本?
/// 返回指定字符串的汉语拼音首字母
/// </summary>
/// <param name="strText"></param>
/// <returns></returns>
public static string GetChineseSpell(string strText)
{
if (Empty.IsEmpty(strText)) return "";
int len = strText.Length;
string myStr = "";
for (int i = 0; i < len; i++)
{
myStr += getSpell(strText.Substring(i, 1));
}
return myStr;
}private static string getSpell(string cnChar)
{
byte[] arrCN = System.Text.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 System.Text.Encoding.Default.GetString(new byte[] { (byte)(65 + i) });
}
}
return "*";
}
else
return cnChar;
}
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data; namespace winet
{
/// <summary>
/// classfun 的摘要说明。
/// </summary>
public class classfun
{
private string capstr; public classfun()
{
//
// todo: 在此处添加构造函数逻辑
//
}
public string chinesecap(string chinesestr)
{
byte[] zw = new byte[2];
long chinesestr_int;
string charstr,chinastr="";
for (int i=0;i<=chinesestr.length-1;i++)
{
charstr=chinesestr.substring(i,1).tostring();
zw=system.text.encoding.default.getbytes(charstr);
// 得到汉字符的字节数组
if(zw.length==2)
{
int i1 = (short)(zw[0]);
int i2 = (short)(zw[1]);
chinesestr_int=i1*256+i2;
//table of the constant list
// a; //45217..45252
// b; //45253..45760
// c; //45761..46317
// d; //46318..46825
// e; //46826..47009
// f; //47010..47296
// g; //47297..47613 // h; //47614..48118
// j; //48119..49061
// k; //49062..49323
// l; //49324..49895
// m; //49896..50370
// n; //50371..50613
// o; //50614..50621
// p; //50622..50905
// q; //50906..51386 // r; //51387..51445
// s; //51446..52217
// t; //52218..52697
//没有u,v
// w; //52698..52979
// x; //52980..53640
// y; //53689..54480
// z; //54481..55289 if ((chinesestr_int>=45217) && (chinesestr_int<=45252))
{
chinastr= "a";
}
else if ((chinesestr_int>=45253) && (chinesestr_int<=45760))
{
chinastr= "b";
}
else if ((chinesestr_int>=45761) && (chinesestr_int<=46317))
{
chinastr= "c"; }
else if ((chinesestr_int>=46318) && (chinesestr_int<=46825))
{
chinastr= "d";
}
else if ((chinesestr_int>=46826) && (chinesestr_int<=47009))
{
chinastr= "e";
}
else if ((chinesestr_int>=47010) && (chinesestr_int<=47296))
{
chinastr= "f";
}
else if ((chinesestr_int>=47297) && (chinesestr_int<=47613))
{
chinastr= "g";
}
else if ((chinesestr_int>=47614) && (chinesestr_int<=48118))
{ chinastr= "h";
} else if ((chinesestr_int>=48119) && (chinesestr_int<=49061))
{
chinastr= "j";
}
else if ((chinesestr_int>=49062) && (chinesestr_int<=49323))
{
chinastr= "k";
}
else if ((chinesestr_int>=49324) && (chinesestr_int<=49895))
{
chinastr= "l";
}
else if ((chinesestr_int>=49896) && (chinesestr_int<=50370))
{
chinastr= "m";
} else if ((chinesestr_int>=50371) && (chinesestr_int<=50613))
{
chinastr= "n"; }
else if ((chinesestr_int>=50614) && (chinesestr_int<=50621))
{
chinastr= "o";
}
else if ((chinesestr_int>=50622) && (chinesestr_int<=50905))
{
chinastr= "p"; }
else if ((chinesestr_int>=50906) && (chinesestr_int<=51386))
{
chinastr= "q"; } else if ((chinesestr_int>=51387) && (chinesestr_int<=51445))
{
chinastr= "r";
}
else if ((chinesestr_int>=51446) && (chinesestr_int<=52217))
{
chinastr= "s";
}
else if ((chinesestr_int>=52218) && (chinesestr_int<=52697))
{
chinastr= "t";
}
else if ((chinesestr_int>=52698) && (chinesestr_int<=52979))
{
chinastr= "w";
}
else if ((chinesestr_int>=52980) && (chinesestr_int<=53640))
{
chinastr= "x";
}
else if ((chinesestr_int>=53689) && (chinesestr_int<=54480))
{
chinastr= "y";
}
else if ((chinesestr_int>=54481) && (chinesestr_int<=55289))
{
chinastr= "z";
} }
else
{
capstr=chinesestr;
break;
} capstr=capstr+chinastr;
} return capstr; }
}
}
google一下。