asp.Net漢字変換ピンインと頭文字実現コード


Default.aspxページ
 
   
 
 
 
 
 
 
 
 
 

 

 
 
 
 
 
 

Default.aspx.csバックグラウンドコード
 
   
protected void Page_Load(object sender, EventArgs e)  
{  
}  
protected void btnGo_Click(object sender, EventArgs e)  
{  
if (txtChn.Text.Trim() != "")  
lbPinyin.Text =" :"+ StrToPinyin.GetChineseSpell(txtChn.Text)+"
:"+ConvertHzToPz_Gb2312.Convert(txtChn.Text);  
}  

漢字変換の頭文字StrToPinyin.csクラス
 
   
public class StrToPinyin  
{  
public StrToPinyin()  
{}  
private static string[] strChineseCharList =  
{  
#region  
"A " ,  
"A " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"B " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"C " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"D " ,  
"E " ,  
"E " ,  
"F " ,  
"F " ,  
"F " ,  
"F " ,  
"F " ,  
"F " ,  
"F " ,  
"F " , //5_1_a_s_p_x.c_o_m  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"G " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"H " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"J " ,  
"K " ,  
"K " ,  
"K " ,  
"K " ,  
"K " ,  
"K " ,  
"K " ,  
"K " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " ,  
"L " , //5_1_a_s_p_x.c_o_m  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"M " ,  
"N " ,  
"N " ,  
"N " ,  
"N " ,  
"N " ,  
"N " ,  
"O " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"P " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"Q " ,  
"R " ,  
"R " ,  
"R " ,  
"R " ,  
"R " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"S " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,  
"T " ,
"U " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"W " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"X " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y " ,  
"Y ",  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z " ,  
"Z "  
#endregion  
};  
///  
///  
///
 
///  
/// ,  
public static string GetChineseSpell(string strText)  
{  
if (strText == null || strText.Length == 0)  
return strText;  
System.Text.StringBuilder myStr = new System.Text.StringBuilder();  
foreach (char vChar in strText)  
{  
//  
if ((vChar >= 'a' && vChar <= 'z') || (vChar >= 'A' && vChar <= 'Z'))  
myStr.Append(char.ToUpper(vChar));  
else if ((int)vChar >= 19968 && (int)vChar <= 40869)  
{  
// Unicode  
foreach (string strList in strChineseCharList)  
{  
if (strList.IndexOf(vChar) > 0)  
{  
myStr.Append(strList[0]);  
break;  
}  
}  
}  
}  
return myStr.ToString();  
}// GetChineseSpell  
}  

漢字変換ピンインConvertHzToPz_Gb2312.csクラス
 
   
public class ConvertHzToPz_Gb2312  
{  
public ConvertHzToPz_Gb2312()  
{  
//  
// TODO: Add constructor logic here  
//  
}  
#region //gb2312  
//01-09 。  
//16-55 , 。  
//56-87 , / 。  
// 。 “ ”, “ ”。  
//“ ” 0xA1-0xF7( 01-87 0xA0),“ ” 0xA1-0xFE( 01-94 0xA0)。  
// “ ” , 0xB0A1 。( :0xB0=0xA0+16,0xA1=0xA0+1)。  
// :http://www.51aspx.com/CV/HanZiZhuanPinYin  
private static readonly string[][] _Allhz =  
new string[][]  
{  
new string[]{"A"," "},  
new string[]{"Ai"," "},  
new string[]{"An"," "},  
new string[]{"Ang"," "},  
new string[]{"Ao"," "},  
new string[]{"Ba"," "},  
new string[]{"Bai"," "},  
new string[]{"Ban"," "},  
new string[]{"Bang"," "},  
new string[]{"Bao"," "},  
new string[]{"Be"," "},  
new string[]{"Bei"," "},  
new string[]{"Ben"," "},  
new string[]{"Beng"," "},  
new string[]{"Bi"," "},  
new string[]{"Bia"," "},  
new string[]{"Bian"," "},  
new string[]{"Biao"," "},  
new string[]{"Bie"," "},  
new string[]{"Bin"," "},  
new string[]{"Bing"," "},  
new string[]{"Bo"," "},  
new string[]{"Bu"," "},  
new string[]{"Ca"," "},  
new string[]{"Cai"," "},  
new string[]{"Can"," "},  
new string[]{"Cang"," "},  
new string[]{"Cao"," "},  
new string[]{"Ce"," "},  
new string[]{"Cen"," "},  
new string[]{"Ceng"," "},  
new string[]{"Ceok"," "},  
new string[]{"Ceom"," "},  
new string[]{"Ceon"," "},  
new string[]{"Ceor"," "},  
new string[]{"Cha"," "},  
new string[]{"Chai"," "},  
new string[]{"Chan"," "},  
new string[]{"Chang"," "},  
new string[]{"Chao"," "},  
new string[]{"Che"," "},  
new string[]{"Chen"," "},  
new string[]{"Cheng"," "},  
new string[]{"Chi"," "},  
new string[]{"Chong"," "},  
new string[]{"Chou"," "},  
new string[]{"Chu"," "},  
new string[]{"Chua"," "},  
new string[]{"Chuai"," "},  
new string[]{"Chuan"," "},  
new string[]{"Chuang"," "},  
new string[]{"Chui"," "},  
new string[]{"Chun"," "},  
new string[]{"Chuo"," "},  
new string[]{"Ci"," "},  
new string[]{"Cis"," "},  
new string[]{"Cong"," "},  
new string[]{"Cou"," "},  
new string[]{"Cu"," "},  
new string[]{"Cuan"," "},  
new string[]{"Cui"," "},  
new string[]{"Cun"," "},  
new string[]{"Cuo"," "},  
new string[]{"Da"," "},  
new string[]{"Dai"," "},  
new string[]{"Dan"," "},  
new string[]{"Dang"," "},  
new string[]{"Dao"," "},  
new string[]{"De"," "},  
new string[]{"Dei"," "},  
new string[]{"Dem"," "},//51aspx.com  
new string[]{"Den"," "},  
new string[]{"Deng"," "},  
new string[]{"Di"," "},  
new string[]{"Dia"," "},  
new string[]{"Dian"," "},  
new string[]{"Diao"," "},  
new string[]{"Die"," "},  
new string[]{"Dim"," "},  
new string[]{"Ding"," "},  
new string[]{"Diu"," "},  
new string[]{"Dong"," "},  
new string[]{"Dou"," "},  
new string[]{"Du"," "},  
new string[]{"Duan"," "},  
new string[]{"Dui"," "},  
new string[]{"Dul"," "},  
new string[]{"Dun"," "},  
new string[]{"Duo","
 
   
"},  
new string[]{"E"," "},  
new string[]{"En"," "},//5_1_a_s_p_x.c_o_m  
new string[]{"Eng"," "},  
new string[]{"Eo"," "},  
new string[]{"Eol"," "},  
new string[]{"Eom"," "},////5_1_a_s_p_x.c_o_m  
new string[]{"Eos"," "},  
new string[]{"Er"," "},  
new string[]{"Fa"," "},  
new string[]{"Fan"," "},  
new string[]{"Fang"," "},  
new string[]{"Fei"," "},  
new string[]{"Fen"," "},  
new string[]{"Feng"," "},  
new string[]{"Fo"," "},  
new string[]{"Fou"," "},//5_1_a_s_p_x.c_o_m  
new string[]{"Fu"," "},  
new string[]{"Ga"," "},  
new string[]{"Gad"," "},  
new string[]{"Gai"," "},  
new string[]{"Gan"," "},  
new string[]{"Gang"," "},  
new string[]{"Gao"," "},  
new string[]{"Ge"," "},  
new string[]{"Gei"," "},  
new string[]{"Gen"," "},  
new string[]{"Geng"," "},  
new string[]{"Gib"," "},  
new string[]{"Go"," "},//5_1_a_s_p_x.c_o_m  
new string[]{"Gong"," "},  
new string[]{"Gou"," "},  
new string[]{"Gu"," "},  
new string[]{"Gua"," "},  
new string[]{"Guai"," "},  
new string[]{"Guan"," "},  
new string[]{"Guang"," "},  
new string[]{"Gui"," "},  
new string[]{"Gun"," "},  
new string[]{"Guo"," "},  
new string[]{"Ha"," "},  
new string[]{"Hai"," "},  
new string[]{"Hal"," "},  
new string[]{"Han"," "},  
new string[]{"Hang"," "},  
new string[]{"Hao"," "},  
new string[]{"He"," "},  
new string[]{"Hei"," "},  
new string[]{"Hen"," "},  
new string[]{"Heng"," "},  
new string[]{"Ho"," "},//5_1_a_s_p_x.c_o_m  
new string[]{"Hol"," "},  
new string[]{"Hong"," "},  
new string[]{"Hou"," "},  
new string[]{"Hu"," "},  
new string[]{"Hua"," "},  
new string[]{"Huai"," "},  
new string[]{"Huan"," "},  
new string[]{"Huang"," "},  
new string[]{"Hui"," "},  
new string[]{"Hun"," "},  
new string[]{"Huo"," "},  
new string[]{"Hwa"," "},  
new string[]{"I"," "},  
new string[]{"Ji"," "},  
new string[]{"Jia"," "},  
new string[]{"Jian"," "},  
new string[]{"Jiang"," "},  
new string[]{"Jiao"," "},  
new string[]{"Jie"," "},  
new string[]{"Jin"," "},  
new string[]{"Jing"," "},  
new string[]{"Jiong"," "},  
new string[]{"Jiu"," "},  
new string[]{"Jou"," "},  
new string[]{"Ju"," "},  
new string[]{"Juan"," "},  
new string[]{"Jue"," "},  
new string[]{"Jun"," "},  
new string[]{"Ka"," "},  
new string[]{"Kai"," "},  
new string[]{"Kal"," "},//5_1_a_s_p_x.c_o_m  
new string[]{"Kan"," "},  
new string[]{"Kang"," "},  
new string[]{"Kao"," "},  
new string[]{"Ke"," "},  
new string[]{"Kei"," "},  
new string[]{"Ken"," "},  
new string[]{"Keng"," "},  
new string[]{"Ki"," "},  
new string[]{"Kong"," "},  
new string[]{"Kos"," "},  
new string[]{"Kou"," "},  
new string[]{"Ku"," "},  
new string[]{"Kua"," "},  
new string[]{"Kuai"," "},  
new string[]{"Kuan"," "},  
new string[]{"Kuang"," "},  
new string[]{"Kui"," "},  
new string[]{"Kun"," "},  
new string[]{"Kuo"," "},  
new string[]{"Kweok"," "},  
new string[]{"Kwi"," "},  
new string[]{"La"," "},  
new string[]{"Lai"," "},  
new string[]{"Lan"," "},  
new string[]{"Lang"," "},  
new string[]{"Lao"," "},  
new string[]{"Le"," "},  
new string[]{"Lei"," "},  
new string[]{"Li"," "},  
new string[]{"Lia"," "},  
new string[]{"Lian"," "},  
new string[]{"Liang"," "},  
new string[]{"Liao"," "},  
new string[]{"Lie"," "},  
new string[]{"Lin"," "},  
new string[]{"Ling"," "},  
new string[]{"Liu"," "},  
new string[]{"Lo"," "},  
new string[]{"Long"," "},  
new string[]{"Lou"," "},  
new string[]{"Lu"," "},  
new string[]{"Luan"," "},  
new string[]{"Lue"," "},  
new string[]{"Lun"," "},  
new string[]{"Luo"," "},  
new string[]{"Lv"," "},  
new string[]{"M"," "},  
new string[]{"Ma"," "},  
new string[]{"Mai"," "},  
new string[]{"Man"," "},  
new string[]{"Mang"," "},  
new string[]{"Mao"," "},  
new string[]{"Me"," "},  
new string[]{"Mei"," "},  
new string[]{"Men"," "},  
new string[]{"Meng"," "},  
new string[]{"Meo"," "},  
new string[]{"Mi"," "},  
new string[]{"Mian"," "},  
new string[]{"Miao"," "},  
new string[]{"Mie"," "},  
new string[]{"Min"," "},  
new string[]{"Ming"," "},  
new string[]{"Miu"," "},  
new string[]{"Mo"," "},  
new string[]{"Mou"," "},  
new string[]{"Mu"," "},  
new string[]{"Myeo"," "},  
new string[]{"Myeon"," "},  
new string[]{"Myeong"," "},  
new string[]{"N"," "},  
new string[]{"Na"," "},  
new string[]{"Nai"," "},  
new string[]{"Nan"," "},  
new string[]{"Nang"," "},  
new string[]{"Nao"," "},  
new string[]{"Ne"," "},  
new string[]{"Nei"," "},  
new string[]{"Nem"," "},  
new string[]{"Nen"," "},  
new string[]{"Neng"," "},  
new string[]{"Neus"," "},  
new string[]{"Ng"," "},  
new string[]{"Ngag"," "},  
new string[]{"Ngai"," "},  
new string[]{"Ngam"," "},  
new string[]{"Ni"," "},  
new string[]{"Nian"," "},  
new string[]{"Niao"," "},  
new string[]{"Nie"," "},  
new string[]{"Nin"," "},  
new string[]{"Ning"," "},  
new string[]{"Niu"," "},  
new string[]{"Nong"," "},  
new string[]{"Nou"," "},  
new string[]{"Nu"," "},  
new string[]{"Nuan"," "},  
new string[]{"Nue"," "},  
new string[]{"Nun"," "},  
new string[]{"Nung"," "},  
new string[]{"Nuo"," "},  
new string[]{"Nv"," "},  
new string[]{"Nve"," "},  
new string[]{"O"," "},  
new string[]{"Oes"," "},  
new string[]{"Ol"," "},  
new string[]{"On"," "},  
new string[]{"Ou"," "},  
new string[]{"Pa"," "},  
new string[]{"Pai"," "},  
new string[]{"Pak"," "},  
new string[]{"Pan"," "},  
new string[]{"Pang"," "},  
new string[]{"Pao"," "},  
new string[]{"Pei"," "},  
new string[]{"Pen"," "},  
new string[]{"Peng"," "},  
new string[]{"Peol"," "},  
new string[]{"Phas"," "},  
new string[]{"Phdeng"," "},  
new string[]{"Phoi"," "},  
new string[]{"Phos"," "},  
new string[]{"Pi"," "},  
new string[]{"Pian"," "},  
new string[]{"Piao"," "},  
new string[]{"Pie"," "},  
new string[]{"Pin"," "},  
new string[]{"Ping"," "},  
new string[]{"Po"," "},  
new string[]{"Pou"," "},  
new string[]{"Ppun"," "},  
new string[]{"Pu"," "},  
new string[]{"Q"," "},  
new string[]{"Qi"," "},  
new string[]{"Qia"," "},  
new string[]{"Qian"," "},  
new string[]{"Qiang"," "},  
new string[]{"Qiao"," "},  
new string[]{"Qie"," "},  
new string[]{"Qin"," "},  
new string[]{"Qing"," "},  
new string[]{"Qiong"," "},  
new string[]{"Qiu"," "},  
new string[]{"Qu"," "},  
new string[]{"Quan"," "},  
new string[]{"Que"," "},  
new string[]{"Qun"," "},  
new string[]{"Ra"," "},  
new string[]{"Ram"," "},  
new string[]{"Ran"," "},  
new string[]{"Rang"," "},  
new string[]{"Rao"," "},  
new string[]{"Re"," "},  
new string[]{"Ren"," "},  
new string[]{"Ri"," "},  
new string[]{"Rong"," "},  
new string[]{"Rou"," "},  
new string[]{"Ru"," "},  
new string[]{"Rua"," "},  
new string[]{"Ruan"," "},  
new string[]{"Rui"," "},  
new string[]{"Run"," "},  
new string[]{"Ruo"," "},  
new string[]{"Sa"," "},  
new string[]{"Saeng"," "},  
new string[]{"Sai"," "},  
new string[]{"Sal"," "},  
new string[]{"San"," "},  
new string[]{"Sang"," "},  
new string[]{"Sao"," "},  
new string[]{"Se"," "},  
new string[]{"Sed"," "},  
new string[]{"Sei"," "},  
new string[]{"Sen"," "},  
new string[]{"Seng"," "},  
new string[]{"Seo"," "},  
new string[]{"Seon"," "},  
new string[]{"Sha"," "},  
new string[]{"Shai"," "},  
new string[]{"Shan"," "},  
new string[]{"Shang"," "},  
new string[]{"Shao"," "},  
new string[]{"She"," "},  
new string[]{"Shen"," "},  
new string[]{"Sheng"," "},  
new string[]{"Shi"," "},  
new string[]{"Shou"," "},  
new string[]{"Shu"," "},  
new string[]{"Shua"," "},  
new string[]{"Shuai"," "},  
new string[]{"Shuan"," "},  
new string[]{"Shuang"," "},  
new string[]{"Shui"," "},  
new string[]{"Shun"," "},  
new string[]{"Shuo"," "},  
new string[]{"Shw"," "},  
new string[]{"Si"," "},  
new string[]{"So"," "},  
new string[]{"Sol"," "},  
new string[]{"Song"," "},  
new string[]{"Sou"," "},  
new string[]{"Su"," "},  
new string[]{"Suan"," "},  
new string[]{"Sui"," "},  
new string[]{"Sun"," "},  
new string[]{"Suo"," "},  
new string[]{"Ta"," "},  
new string[]{"Tae"," "},  
new string[]{"Tai"," "},  
new string[]{"Tan"," "},  
new string[]{"Tang"," "},  
new string[]{"Tao"," "},  
new string[]{"Teng"," "},  
new string[]{"Ti"," "},  
new string[]{"Tian"," "},  
new string[]{"Tiao"," "},  
new string[]{"Tie"," "},  
new string[]{"Ting"," "},  
new string[]{"Tol"," "},  
new string[]{"Ton"," "},  
new string[]{"Tong"," "},  
new string[]{"Tou"," "},  
new string[]{"Tu"," "},  
new string[]{"Tuan"," "},  
new string[]{"Tui"," "},  
new string[]{"Tun"," "},  
new string[]{"Tuo"," "},  
new string[]{"Uu"," "},  
new string[]{"Wa"," "},  
new string[]{"Wai"," "},  
new string[]{"Wan"," "},  
new string[]{"Wang"," "},  
new string[]{"Wei"," "},  
new string[]{"Wen"," "},  
new string[]{"Weng"," "},  
new string[]{"Wie"," "},  
new string[]{"Wo"," "},  
new string[]{"Wu"," "},  
new string[]{"Xi"," "},  
new string[]{"Xia"," "},  
new string[]{"Xian"," "},  
new string[]{"Xiang"," "},  
new string[]{"Xiao"," "},  
new string[]{"Xie"," "},  
new string[]{"Xin"," "},  
new string[]{"Xing"," "},  
new string[]{"Xiong"," "},  
new string[]{"Xiu"," "},  
new string[]{"Xu"," "},  
new string[]{"Xuan"," "},  
new string[]{"Xue"," "},  
new string[]{"Xun"," "},  
new string[]{"Ya"," "},  
new string[]{"Yan"," "},  
new string[]{"Yang"," "},  
new string[]{"Yao"," "},  
new string[]{"Ye"," "},  
new string[]{"Yi"," "},  
new string[]{"Yin"," "},  
new string[]{"Ying"," "},  
new string[]{"Yo"," "},  
new string[]{"Yong"," "},  
new string[]{"You"," "},  
new string[]{"Yu"," "},  
new string[]{"Yuan"," "},  
new string[]{"Yue"," "},  
new string[]{"Yun"," "},  
new string[]{"Za"," "},  
new string[]{"Zad"," "},  
new string[]{"Zai"," "},  
new string[]{"Zan"," "},  
new string[]{"Zang"," "},  
new string[]{"Zao"," "},  
new string[]{"Ze"," "},  
new string[]{"Zei"," "},  
new string[]{"Zen"," "},  
new string[]{"Zeng"," "},  
new string[]{"Zha"," "},  
new string[]{"Zhai"," "},  
new string[]{"Zhan"," "},  
new string[]{"Zhang"," "},  
new string[]{"Zhao"," "},  
new string[]{"Zhe"," "},  
new string[]{"Zhen"," "},  
new string[]{"Zheng"," "},  
new string[]{"Zhi"," "},  
new string[]{"Zhong"," "},  
new string[]{"Zhou"," "},  
new string[]{"Zhu"," "},  
new string[]{"Zhua"," "},  
new string[]{"Zhuai"," "},  
new string[]{"Zhuan"," "},  
new string[]{"Zhuang"," "},  
new string[]{"Zhui"," "},  
new string[]{"Zhun"," "},  
new string[]{"Zhuo"," "},  
new string[]{"Zi"," "},  
new string[]{"Zo"," "},  
new string[]{"Zong"," "},  
new string[]{"Zou"," "},  
new string[]{"Zu"," "},  
new string[]{"Zuan"," "},  
new string[]{"Zui"," "},  
new string[]{"Zun"," "},  
new string[]{"Zuo"," "}  
};  
#endregion  
public static string Convert(string str)  
{  
if (str == null )  
return null;  
Encoding ed = Encoding.GetEncoding("GB2312");  
if (ed == null)  
throw (new ArgumentException(" GB2312"));  
int bh = 0;  
char[] charary = str.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();  
}  
}  
 
 
JS

Jsをフロントページに適用するか、Jsパッケージに入れてフロントコール
//JavaScript Document function ChineseToEnglish(ChinaText) {      var  str ="";     for(var i=0;i    var temp =  toPinyinOnly(ChinaText.substr(i,1));      temp = temp.substr(0,1);      str += temp;     }     str = str.toUpperCase();        return str; } function isChinese(str) {       if(""==str){       return false;          }        return true; }//漢字変換function pinyin(char){var spellArray=new Array();var tx=char execScript("ascCode=hex(asc("+char+""""""""");"vbscript"); ascCode=eval("0 x"+ascCode);if(event.keyCode=13)event.keyCode=9;else if(!char.charCodeAt(0)|char.charCodeAt(0)|char.charCodeAt(0)<1328){               return tx; }           else if (!(ascCode > 0xB0A0 && ascCode < 0xD7FC)){               return tx;}           else {            for (var i = ascCode; !spell[i] && i > 0;)              i--; return spell[i]}function toPinyinOnly(str){var pStr=""for(var i=0;i if(str.charAt(i)="r"){//重要!リターン入力のBugを解決!!pStr+="r";i++;           }           else {           pStr += pinyin(str.charAt(i)) + "";             }}           return pStr;         }
//ピンイン変換コード
var spell = {        0xB0A1:"a", 0xB0A3:"ai", 0xB0B0:"an", 0xB0B9:"ang", 0xB0BC:"ao",        0xB0C5:"ba", 0xB0D7:"bai", 0xB0DF:"ban", 0xB0EE:"bang", 0xB0FA:"bao",        0xB1AD:"bei", 0xB1BC:"ben", 0xB1C0:"beng", 0xB1C6:"bi", 0xB1DE:"bian",        0xB1EA:"biao", 0xB1EE:"bie", 0xB1F2:"bin", 0xB1F8:"bing", 0xB2A3:"bo",        0xB2B8:"bu", 0xB2C1:"ca", 0xB2C2:"cai", 0xB2CD:"can", 0xB2D4:"cang",        0xB2D9:"cao", 0xB2DE:"ce", 0xB2E3:"ceng", 0xB2E5:"cha", 0xB2F0:"chai",        0xB2F3:"chan", 0xB2FD:"chang", 0xB3AC:"chao", 0xB3B5:"che", 0xB3BB:"chen",        0xB3C5:"cheng", 0xB3D4:"chi", 0xB3E4:"chong", 0xB3E9:"chou", 0xB3F5:"chu",        0xB4A7:"chuai", 0xB4A8:"chuan", 0xB4AF:"chuang", 0xB4B5:"chui", 0xB4BA:"chun",        0xB4C1:"chuo", 0xB4C3:"ci", 0xB4CF:"cong", 0xB4D5:"cou", 0xB4D6:"cu",        0xB4DA:"cuan", 0xB4DD:"cui", 0xB4E5:"cun", 0xB4E8:"cuo", 0xB4EE:"da",        0xB4F4:"dai", 0xB5A2:"dan", 0xB5B1:"dang", 0xB5B6:"dao", 0xB5C2:"de",        0xB5C5:"deng", 0xB5CC:"di", 0xB5DF:"dian", 0xB5EF:"diao", 0xB5F8:"die",        0xB6A1:"ding", 0xB6AA:"diu", 0xB6AB:"dong", 0xB6B5:"dou", 0xB6BC:"du",        0xB6CB:"duan", 0xB6D1:"dui", 0xB6D5:"dun", 0xB6DE:"duo", 0xB6EA:"e",        0xB6F7:"en", 0xB6F8:"er", 0xB7A2:"fa", 0xB7AA:"fan", 0xB7BB:"fang",        0xB7C6:"fei", 0xB7D2:"fen", 0xB7E1:"feng", 0xB7F0:"fo", 0xB7F1:"fou",        0xB7F2:"fu", 0xB8C1:"ga", 0xB8C3:"gai", 0xB8C9:"gan", 0xB8D4:"gang",        0xB8DD:"gao", 0xB8E7:"ge", 0xB8F8:"gei", 0xB8F9:"gen", 0xB8FB:"geng",        0xB9A4:"gong", 0xB9B3:"gou", 0xB9BC:"gu", 0xB9CE:"gua", 0xB9D4:"guai",        0xB9D7:"guan", 0xB9E2:"guang", 0xB9E5:"gui", 0xB9F5:"gun", 0xB9F8:"guo",        0xB9FE:"ha", 0xBAA1:"hai", 0xBAA8:"han", 0xBABB:"hang", 0xBABE:"hao",        0xBAC7:"he", 0xBAD9:"hei", 0xBADB:"hen", 0xBADF:"heng", 0xBAE4:"hong",        0xBAED:"hou", 0xBAF4:"hu", 0xBBA8:"hua", 0xBBB1:"huai", 0xBBB6:"huan",        0xBBC4:"huang", 0xBBD2:"hui", 0xBBE7:"hun", 0xBBED:"huo", 0xBBF7:"ji",        0xBCCE:"jia", 0xBCDF:"jian", 0xBDA9:"jiang", 0xBDB6:"jiao", 0xBDD2:"jie",        0xBDED:"jin", 0xBEA3:"jing", 0xBEBC:"jiong", 0xBEBE:"jiu", 0xBECF:"ju",        0xBEE8:"juan", 0xBEEF:"jue", 0xBEF9:"jun", 0xBFA6:"ka", 0xBFAA:"kai",        0xBFAF:"kan", 0xBFB5:"kang", 0xBFBC:"kao", 0xBFC0:"ke", 0xBFCF:"ken",        0xBFD3:"keng", 0xBFD5:"kong", 0xBFD9:"kou", 0xBFDD:"ku", 0xBFE4:"kua",        0xBFE9:"kuai", 0xBFED:"kuan", 0xBFEF:"kuang", 0xBFF7:"kui", 0xC0A4:"kun",        0xC0A8:"kuo", 0xC0AC:"la", 0xC0B3:"lai", 0xC0B6:"lan", 0xC0C5:"lang",        0xC0CC:"lao", 0xC0D5:"le", 0xC0D7:"lei", 0xC0E2:"leng", 0xC0E5:"li",        0xC1A9:"lia", 0xC1AA:"lian", 0xC1B8:"liang", 0xC1C3:"liao", 0xC1D0:"lie",        0xC1D5:"lin", 0xC1E1:"ling", 0xC1EF:"liu", 0xC1FA:"long", 0xC2A5:"lou",        0xC2AB:"lu", 0xC2BF:"lv", 0xC2CD:"luan", 0xC2D3:"lue", 0xC2D5:"lun",        0xC2DC:"luo", 0xC2E8:"ma", 0xC2F1:"mai", 0xC2F7:"man", 0xC3A2:"mang",        0xC3A8:"mao", 0xC3B4:"me", 0xC3B5:"mei", 0xC3C5:"men", 0xC3C8:"meng",        0xC3D0:"mi", 0xC3DE:"mian", 0xC3E7:"miao", 0xC3EF:"mie", 0xC3F1:"min",        0xC3F7:"ming", 0xC3FD:"miu", 0xC3FE:"mo", 0xC4B1:"mou", 0xC4B4:"mu",        0xC4C3:"na", 0xC4CA:"nai", 0xC4CF:"nan", 0xC4D2:"nang", 0xC4D3:"nao",        0xC4D8:"ne", 0xC4D9:"nei", 0xC4DB:"nen", 0xC4DC:"neng", 0xC4DD:"ni",        0xC4E8:"nian", 0xC4EF:"niang", 0xC4F1:"niao", 0xC4F3:"nie", 0xC4FA:"nin",        0xC4FB:"ning", 0xC5A3:"niu", 0xC5A7:"nong", 0xC5AB:"nu", 0xC5AE:"nv",        0xC5AF:"nuan", 0xC5B0:"nue", 0xC5B2:"nuo", 0xC5B6:"o", 0xC5B7:"ou",        0xC5BE:"pa", 0xC5C4:"pai", 0xC5CA:"pan", 0xC5D2:"pang", 0xC5D7:"pao",        0xC5DE:"pei", 0xC5E7:"pen", 0xC5E9:"peng", 0xC5F7:"pi", 0xC6AA:"pian",        0xC6AE:"piao", 0xC6B2:"pie", 0xC6B4:"pin", 0xC6B9:"ping", 0xC6C2:"po",        0xC6CB:"pu", 0xC6DA:"qi", 0xC6FE:"qia", 0xC7A3:"qian", 0xC7B9:"qiang",        0xC7C1:"qiao", 0xC7D0:"qie", 0xC7D5:"qin", 0xC7E0:"qing", 0xC7ED:"qiong",        0xC7EF:"qiu", 0xC7F7:"qu", 0xC8A6:"quan", 0xC8B1:"que", 0xC8B9:"qun",        0xC8BB:"ran", 0xC8BF:"rang", 0xC8C4:"rao", 0xC8C7:"re", 0xC8C9:"ren",        0xC8D3:"reng", 0xC8D5:"ri", 0xC8D6:"rong", 0xC8E0:"rou", 0xC8E3:"ru",        0xC8ED:"ruan", 0xC8EF:"rui", 0xC8F2:"run", 0xC8F4:"ruo", 0xC8F6:"sa",        0xC8F9:"sai", 0xC8FD:"san", 0xC9A3:"sang", 0xC9A6:"sao", 0xC9AA:"se",        0xC9AD:"sen", 0xC9AE:"seng", 0xC9AF:"sha", 0xC9B8:"shai", 0xC9BA:"shan",        0xC9CA:"shang", 0xC9D2:"shao", 0xC9DD:"she", 0xC9E9:"shen", 0xC9F9:"sheng",        0xCAA6:"shi", 0xCAD5:"shou", 0xCADF:"shu", 0xCBA2:"shua", 0xCBA4:"shuai",        0xCBA8:"shuan", 0xCBAA:"shuang", 0xCBAD:"shui", 0xCBB1:"shun", 0xCBB5:"shuo",        0xCBB9:"si", 0xCBC9:"song", 0xCBD1:"sou", 0xCBD4:"su", 0xCBE1:"suan",        0xCBE4:"sui", 0xCBEF:"sun", 0xCBF2:"suo", 0xCBFA:"ta", 0xCCA5:"tai",        0xCCAE:"tan", 0xCCC0:"tang", 0xCCCD:"tao", 0xCCD8:"te", 0xCCD9:"teng",        0xCCDD:"ti", 0xCCEC:"tian", 0xCCF4:"tiao", 0xCCF9:"tie", 0xCCFC:"ting",        0xCDA8:"tong", 0xCDB5:"tou", 0xCDB9:"tu", 0xCDC4:"tuan", 0xCDC6:"tui",        0xCDCC:"tun", 0xCDCF:"tuo", 0xCDDA:"wa", 0xCDE1:"wai", 0xCDE3:"wan",        0xCDF4:"wang", 0xCDFE:"wei", 0xCEC1:"wen", 0xCECB:"weng", 0xCECE:"wo",        0xCED7:"wu", 0xCEF4:"xi", 0xCFB9:"xia", 0xCFC6:"xian", 0xCFE0:"xiang",        0xCFF4:"xiao", 0xD0A8:"xie", 0xD0BD:"xin", 0xD0C7:"xing", 0xD0D6:"xiong",        0xD0DD:"xiu", 0xD0E6:"xu", 0xD0F9:"xuan", 0xD1A5:"xue", 0xD1AB:"xun",        0xD1B9:"ya", 0xD1C9:"yan", 0xD1EA:"yang", 0xD1FB:"yao", 0xD2AC:"ye",        0xD2BB:"yi", 0xD2F0:"yin", 0xD3A2:"ying", 0xD3B4:"yo", 0xD3B5:"yong",        0xD3C4:"you", 0xD3D9:"yu", 0xD4A7:"yuan", 0xD4BB:"yue", 0xD4C5:"yun",        0xD4D1:"za", 0xD4D4:"zai", 0xD4DB:"zan", 0xD4DF:"zang", 0xD4E2:"zao",        0xD4F0:"ze", 0xD4F4:"zei", 0xD4F5:"zen", 0xD4F6:"zeng", 0xD4FA:"zha",        0xD5AA:"zhai", 0xD5B0:"zhan", 0xD5C1:"zhang", 0xD5D0:"zhao", 0xD5DA:"zhe",        0xD5E4:"zhen", 0xD5F4:"zheng", 0xD6A5:"zhi", 0xD6D0:"zhong", 0xD6DB:"zhou",        0xD6E9:"zhu", 0xD7A5:"zhua", 0xD7A7:"zhuai", 0xD7A8:"zhuan", 0xD7AE:"zhuang",        0xD7B5:"zhui", 0xD7BB:"zhun", 0xD7BD:"zhuo", 0xD7C8:"zi", 0xD7D7:"zong",        0xD7DE:"zou", 0xD7E2:"zu", 0xD7EA:"zuan", 0xD7EC:"zui", 0xD7F0:"zun", 0xD7F2:"zuo"       };
 
フロントページにJSと書いてあります
 function setvalue(obj) {             var str = ChineseToEnglish(obj);             document.getElementById("txtPY").value = str;
//このテキストボックスのIDは、ターゲットがピンインに変換されたIDです}
テキストボックスにフォーカスを失ったイベントを書き、jsを呼び出します.
(ソーステキストボックス)
(ターゲットテキストボックス)