其实现的原理就是先将汉字转化成为内码然后通过内码和拼音的对照来查找
详细的代码如下所示
public class chspy
{/// ///将汉字转换成为拼音
///作者铁匠(chinahuman)
///完成于年月日早上
///
private static int[] pyvalue=new int[]{
};
private static string[] pystr=new string[]{aaianangaobabaibanbangbaobeibenbengbibianbiao
biebinbingbobucacaicancangcaocecengchachaichanchangchaochechen
chengchichongchouchuchuaichuanchuangchuichunchuocicongcoucucuancui
cuncuodadaidandangdaodedengdidiandiaodiedingdiudongdoududuan
duidunduoeenerfafanfangfeifenfengfofoufugagaiganganggao
gegeigengenggonggouguguaguaiguanguangguigunguohahaihanhang
haoheheihenhenghonghouhuhuahuaihuanhuanghuihunhuojijiajian
jiangjiaojiejinjingjiongjiujujuanjuejunkakaikankangkaokeken
kengkongkoukukuakuaikuankuangkuikunkuolalailanlanglaolelei
lenglilialianliangliaolielinlingliulongloululvluanluelunluo
mamaimanmangmaomemeimenmengmimianmiaomieminmingmiumomoumu
nanainannangnaoneneinennengninianniangniaonieninningniunong
nunvnuannuenuoooupapaipanpangpaopeipenpengpipianpiaopie
pinpingpopuqiqiaqianqiangqiaoqieqinqingqiongqiuququanquequn
ranrangraorerenrengrirongroururuanruirunruosasaisansang
saosesensengshashaishanshangshaosheshenshengshishoushushua
shuaishuanshuangshuishunshuosisongsoususuansuisunsuotatai
tantangtaotetengtitiantiaotietingtongtoututuantuituntuo
wawaiwanwangweiwenwengwowuxixiaxianxiangxiaoxiexinxing
xiongxiuxuxuanxuexunyayanyangyaoyeyiyinyingyoyongyou
yuyuanyueyunzazaizanzangzaozezeizenzengzhazhaizhanzhang
zhaozhezhenzhengzhizhongzhouzhuzhuazhuaizhuanzhuangzhuizhunzhuo
zizongzouzuzuanzuizunzuo};
public chspy()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public static string convert(string chrstr)
{
byte[] array = new byte[];
string returnstr=;
int chrasc=;
int i = ;
int i =;
char[] nowchar=chrstrToCharArray();
for (int j=;j{array = System.Text.Encoding.Default.GetBytes(nowchar[j].ToString ());
i1 = (short)(array[0] );
i2 = (short)(array[1] );
chrasc=i1*256+i2-65536;
if (chrasc> && chrasc<160)
{
returnstr+=nowchar[j];
}
else
{
for (int i=(pyvalue.Length -1);i>=;i)
{
if (pyvalue[i]<=chrasc)
{
returnstr+=pystr[i];
break;
}
}
}
}
return returnstr;
}
}