Code snippet of the day : Get Chinese Spell in C#
2004-05-10 18:00
821 查看
I plan to blog useful code snippets regularly. Just little bits of ActionScript that help me in my day to day coding.
Here is the code.
function ToggleSourceCodeRegion(regionNumber)
{
var divRegion = document.getElementById('region' + regionNumber);
var divRegionBlock = document.getElementById('regionBlock' + regionNumber);
if (divRegion.style.display == 'inline')
{
divRegion.style.display = 'none';
divRegionBlock.style.display = 'inline';
}
else
{
divRegion.style.display = 'inline';
divRegionBlock.style.display = 'none';
}
}
I hope this helps.
Here is the code.
function ToggleSourceCodeRegion(regionNumber)
{
var divRegion = document.getElementById('region' + regionNumber);
var divRegionBlock = document.getElementById('regionBlock' + regionNumber);
if (divRegion.style.display == 'inline')
{
divRegion.style.display = 'none';
divRegionBlock.style.display = 'inline';
}
else
{
divRegion.style.display = 'inline';
divRegionBlock.style.display = 'none';
}
}
1/// <summary> 2/// 获得汉字拼音 3/// </summary> 4/// <param name="strChinese">汉字字符串</param> 5/// <returns>汉字拼音字符串</returns> 6public static string GetSpell(string strChinese) 7{ 8 try 9 { 10 Hashtable baseCodeHashtable=BaseCodeHashtable(); 11 byte[] byteStream=System.Text.Encoding.Default.GetBytes(strChinese); 12 int iBit; 13 StringBuilder stringBuilder=new StringBuilder(); 14 for(int i=0;i< byteStream.Length;i++) 15 { 16 iBit=(int)byteStream; 17 if(iBit>160) 18 { 19 iBit=iBit*256+byteStream[++i]-65536; 20 stringBuilder.Append(GetCharacterByCode(baseCodeHashtable,iBit)); 21 } 22 else 23 { 24 stringBuilder.Append((char)iBit); 25 } 26 } 27 baseCodeHashtable.Clear(); 28 return stringBuilder.ToString(); 29 } 30 catch 31 { 32 return ""; 33 } 34 35} 36 37private string GetCharacterByCode(Hashtable ht,int num) 38{ 39 if(num < -20319||num > -10247) 40 return ""; 41 while(!ht.ContainsKey(num)) 42 num--; 43 return ht[num].ToString(); 44} 45 46private Hashtable BaseCodeHashtable() 47{ 48 Hashtable ht=new Hashtable(); 49 ht.Add(-20319,"a"); 50 ht.Add(-20317,"ai");ht.Add(-20304,"an"); ht.Add(-20295,"ang"); 51 ht.Add(-20292,"ao");ht.Add(-20283,"ba"); ht.Add(-20265,"bai"); 52 ht.Add(-20257,"ban");ht.Add(-20242,"bang"); ht.Add(-20230,"bao"); 53 ht.Add(-20051,"bei"); ht.Add(-20036,"ben"); ht.Add(-20032,"beng"); 54 ht.Add(-20026,"bi"); ht.Add(-20002,"bian"); ht.Add(-19990,"biao"); 55 ht.Add(-19986,"bie"); ht.Add(-19982,"bin"); ht.Add(-19976,"bing"); 56 ht.Add(-19805,"bo"); ht.Add(-19784,"bu"); ht.Add(-19775,"ca"); 57 ht.Add(-19774,"cai"); ht.Add(-19763,"can"); ht.Add(-19756,"cang"); 58 ht.Add(-19751,"cao"); ht.Add(-19746,"ce"); ht.Add(-19741,"ceng"); 59 ht.Add(-19739,"cha"); ht.Add(-19728,"chai"); ht.Add(-19725,"chan"); 60 ht.Add(-19715,"chang"); ht.Add(-19540,"chao"); ht.Add(-19531,"che"); 61 ht.Add(-19525,"chen"); ht.Add(-19515,"cheng"); ht.Add(-19500,"chi"); 62 ht.Add(-19484,"chong"); ht.Add(-19479,"chou"); ht.Add(-19467,"chu"); 63 ht.Add(-19289,"chuai"); ht.Add(-19288,"chuan"); ht.Add(-19281,"chuang"); 64 ht.Add(-19275,"chui"); ht.Add(-19270,"chun"); ht.Add(-19263,"chuo"); 65 ht.Add(-19261,"ci"); ht.Add(-19249,"cong"); ht.Add(-19243,"cou"); 66 ht.Add(-19242,"cu"); ht.Add(-19238,"cuan"); ht.Add(-19235,"cui"); 67 ht.Add(-19227,"cun"); ht.Add(-19224,"cuo"); ht.Add(-19218,"da"); 68 ht.Add(-19212,"dai"); ht.Add(-19038,"dan"); ht.Add(-19023,"dang"); 69 ht.Add(-19018,"dao"); ht.Add(-19006,"de"); ht.Add(-19003,"deng"); 70 ht.Add(-18996,"di"); ht.Add(-18977,"dian"); ht.Add(-18961,"diao"); 71 ht.Add(-18952,"die"); ht.Add(-18783,"ding"); ht.Add(-18774,"diu"); 72 ht.Add(-18773,"dong"); ht.Add(-18763,"dou"); ht.Add(-18756,"du"); 73 ht.Add(-18741,"duan"); ht.Add(-18735,"dui"); ht.Add(-18731,"dun"); 74 ht.Add(-18722,"duo"); ht.Add(-18710,"e"); ht.Add(-18697,"en"); 75 ht.Add(-18696,"er"); ht.Add(-18526,"fa"); ht.Add(-18518,"fan"); 76 ht.Add(-18501,"fang"); ht.Add(-18490,"fei"); ht.Add(-18478,"fen"); 77 ht.Add(-18463,"feng"); ht.Add(-18448,"fo"); ht.Add(-18447,"fou"); 78 ht.Add(-18446,"fu"); ht.Add(-18239,"ga"); ht.Add(-18237,"gai"); 79 ht.Add(-18231,"gan"); ht.Add(-18220,"gang"); ht.Add(-18211,"gao"); 80 ht.Add(-18201,"ge"); ht.Add(-18184,"gei"); ht.Add(-18183,"gen"); 81 ht.Add(-18181,"geng"); ht.Add(-18012,"gong"); ht.Add(-17997,"gou"); 82 ht.Add(-17988,"gu"); ht.Add(-17970,"gua"); ht.Add(-17964,"guai"); 83 ht.Add(-17961,"guan"); ht.Add(-17950,"guang"); ht.Add(-17947,"gui"); 84 ht.Add(-17931,"gun"); ht.Add(-17928,"guo"); ht.Add(-17922,"ha"); 85 ht.Add(-17759,"hai"); ht.Add(-17752,"han"); ht.Add(-17733,"hang"); 86 ht.Add(-17730,"hao"); ht.Add(-17721,"he"); ht.Add(-17703,"hei"); 87 ht.Add(-17701,"hen"); ht.Add(-17697,"heng"); ht.Add(-17692,"hong"); 88 ht.Add(-17683,"hou"); ht.Add(-17676,"hu"); ht.Add(-17496,"hua"); 89 ht.Add(-17487,"huai"); ht.Add(-17482,"huan"); ht.Add(-17468,"huang"); 90 ht.Add(-17454,"hui"); ht.Add(-17433,"hun"); ht.Add(-17427,"huo"); 91 ht.Add(-17417,"ji"); ht.Add(-17202,"jia"); ht.Add(-17185,"jian"); 92 ht.Add(-16983,"jiang"); ht.Add(-16970,"jiao"); ht.Add(-16942,"jie"); 93 ht.Add(-16915,"jin"); ht.Add(-16733,"jing"); ht.Add(-16708,"jiong"); 94 ht.Add(-16706,"jiu"); ht.Add(-16689,"ju"); ht.Add(-16664,"juan"); 95 ht.Add(-16657,"jue"); ht.Add(-16647,"jun"); ht.Add(-16474,"ka"); 96 ht.Add(-16470,"kai"); ht.Add(-16465,"kan"); ht.Add(-16459,"kang"); 97 ht.Add(-16452,"kao"); ht.Add(-16448,"ke"); ht.Add(-16433,"ken"); 98 ht.Add(-16429,"keng"); ht.Add(-16427,"kong"); ht.Add(-16423,"kou"); 99 ht.Add(-16419,"ku"); ht.Add(-16412,"kua"); ht.Add(-16407,"kuai"); 100 ht.Add(-16403,"kuan"); ht.Add(-16401,"kuang"); ht.Add(-16393,"kui"); 101 ht.Add(-16220,"kun"); ht.Add(-16216,"kuo"); ht.Add(-16212,"la"); 102 ht.Add(-16205,"lai"); ht.Add(-16202,"lan"); ht.Add(-16187,"lang"); 103 ht.Add(-16180,"lao"); ht.Add(-16171,"le"); ht.Add(-16169,"lei"); 104 ht.Add(-16158,"leng"); ht.Add(-16155,"li"); ht.Add(-15959,"lia"); 105 ht.Add(-15958,"lian"); ht.Add(-15944,"liang"); ht.Add(-15933,"liao"); 106 ht.Add(-15920,"lie"); ht.Add(-15915,"lin"); ht.Add(-15903,"ling"); 107 ht.Add(-15889,"liu"); ht.Add(-15878,"long"); ht.Add(-15707,"lou"); 108 ht.Add(-15701,"lu");ht.Add(-15681,"lv");ht.Add(-15667,"luan"); 109 ht.Add(-15661,"lue");ht.Add(-15659,"lun");ht.Add(-15652,"luo"); 110 ht.Add(-15640,"ma");ht.Add(-15631,"mai");ht.Add(-15625,"man"); 111 ht.Add(-15454,"mang");ht.Add(-15448,"mao");ht.Add(-15436,"me"); 112 ht.Add(-15435,"mei");ht.Add(-15419,"men");ht.Add(-15416,"meng"); 113 ht.Add(-15408,"mi");ht.Add(-15394,"mian");ht.Add(-15385,"miao"); 114 ht.Add(-15377,"mie");ht.Add(-15375,"min");ht.Add(-15369,"ming"); 115 ht.Add(-15363,"miu");ht.Add(-15362,"mo");ht.Add(-15183,"mou"); 116 ht.Add(-15180,"mu");ht.Add(-15165,"na");ht.Add(-15158,"nai"); 117 ht.Add(-15153,"nan");ht.Add(-15150,"nang");ht.Add(-15149,"nao"); 118 ht.Add(-15144,"ne");ht.Add(-15143,"nei");ht.Add(-15141,"nen"); 119 ht.Add(-15140,"neng");ht.Add(-15139,"ni");ht.Add(-15128,"nian"); 120 ht.Add(-15121,"niang");ht.Add(-15119,"niao");ht.Add(-15117,"nie"); 121 ht.Add(-15110,"nin");ht.Add(-15109,"ning");ht.Add(-14941,"niu"); 122 ht.Add(-14937,"nong");ht.Add(-14933,"nu");ht.Add(-14930,"nv"); 123 ht.Add(-14929,"nuan");ht.Add(-14928,"nue");ht.Add(-14926,"nuo"); 124 ht.Add(-14922,"o");ht.Add(-14921,"ou");ht.Add(-14914,"pa"); 125 ht.Add(-14908,"pai");ht.Add(-14902,"pan");ht.Add(-14894,"pang"); 126 ht.Add(-14889,"pao");ht.Add(-14882,"pei");ht.Add(-14873,"pen"); 127 ht.Add(-14871,"peng");ht.Add(-14857,"pi");ht.Add(-14678,"pian"); 128 ht.Add(-14674,"piao");ht.Add(-14670,"pie");ht.Add(-14668,"pin"); 129 ht.Add(-14663,"ping");ht.Add(-14654,"po");ht.Add(-14645,"pu"); 130 ht.Add(-14630,"qi");ht.Add(-14594,"qia");ht.Add(-14429,"qian"); 131 ht.Add(-14407,"qiang");ht.Add(-14399,"qiao");ht.Add(-14384,"qie"); 132 ht.Add(-14379,"qin");ht.Add(-14368,"qing");ht.Add(-14355,"qiong"); 133 ht.Add(-14353,"qiu");ht.Add(-14345,"qu");ht.Add(-14170,"quan"); 134 ht.Add(-14159,"que");ht.Add(-14151,"qun");ht.Add(-14149,"ran"); 135 ht.Add(-14145,"rang");ht.Add(-14140,"rao");ht.Add(-14137,"re"); 136 ht.Add(-14135,"ren");ht.Add(-14125,"reng");ht.Add(-14123,"ri"); 137 ht.Add(-14122,"rong");ht.Add(-14112,"rou");ht.Add(-14109,"ru"); 138 ht.Add(-14099,"ruan");ht.Add(-14097,"rui");ht.Add(-14094,"run"); 139 ht.Add(-14092,"ruo");ht.Add(-14090,"sa");ht.Add(-14087,"sai"); 140 ht.Add(-14083,"san");ht.Add(-13917,"sang");ht.Add(-13914,"sao"); 141 ht.Add(-13910,"se");ht.Add(-13907,"sen");ht.Add(-13906,"seng"); 142 ht.Add(-13905,"sha");ht.Add(-13896,"shai");ht.Add(-13894,"shan"); 143 ht.Add(-13878,"shang");ht.Add(-13870,"shao");ht.Add(-13859,"she"); 144 ht.Add(-13847,"shen");ht.Add(-13831,"sheng");ht.Add(-13658,"shi"); 145 ht.Add(-13611,"shou");ht.Add(-13601,"shu");ht.Add(-13406,"shua"); 146 ht.Add(-13404,"shuai");ht.Add(-13400,"shuan");ht.Add(-13398,"shuang"); 147 ht.Add(-13395,"shui");ht.Add(-13391,"shun");ht.Add(-13387,"shuo"); 148 ht.Add(-13383,"si");ht.Add(-13367,"song");ht.Add(-13359,"sou"); 149 ht.Add(-13356,"su");ht.Add(-13343,"suan");ht.Add(-13340,"sui"); 150 ht.Add(-13329,"sun");ht.Add(-13326,"suo");ht.Add(-13318,"ta"); 151 ht.Add(-13147,"tai");ht.Add(-13138,"tan");ht.Add(-13120,"tang"); 152 ht.Add(-13107,"tao");ht.Add(-13096,"te");ht.Add(-13095,"teng"); 153 ht.Add(-13091,"ti");ht.Add(-13076,"tian");ht.Add(-13068,"tiao"); 154 ht.Add(-13063,"tie");ht.Add(-13060,"ting");ht.Add(-12888,"tong"); 155 ht.Add(-12875,"tou");ht.Add(-12871,"tu");ht.Add(-12860,"tuan"); 156 ht.Add(-12858,"tui");ht.Add(-12852,"tun");ht.Add(-12849,"tuo"); 157 ht.Add(-12838,"wa");ht.Add(-12831,"wai");ht.Add(-12829,"wan"); 158 ht.Add(-12812,"wang");ht.Add(-12802,"wei");ht.Add(-12607,"wen"); 159 ht.Add(-12597,"weng");ht.Add(-12594,"wo");ht.Add(-12585,"wu"); 160 ht.Add(-12556,"xi");ht.Add(-12359,"xia");ht.Add(-12346,"xian"); 161 ht.Add(-12320,"xiang");ht.Add(-12300,"xiao");ht.Add(-12120,"xie"); 162 ht.Add(-12099,"xin");ht.Add(-12089,"xing");ht.Add(-12074,"xiong"); 163 ht.Add(-12067,"xiu");ht.Add(-12058,"xu");ht.Add(-12039,"xuan"); 164 ht.Add(-11867,"xue");ht.Add(-11861,"xun");ht.Add(-11847,"ya"); 165 ht.Add(-11831,"yan");ht.Add(-11798,"yang");ht.Add(-11781,"yao"); 166 ht.Add(-11604,"ye");ht.Add(-11589,"yi");ht.Add(-11536,"yin"); 167 ht.Add(-11358,"ying");ht.Add(-11340,"yo");ht.Add(-11339,"yong"); 168 ht.Add(-11324,"you");ht.Add(-11303,"yu");ht.Add(-11097,"yuan"); 169 ht.Add(-11077,"yue");ht.Add(-11067,"yun");ht.Add(-11055,"za"); 170 ht.Add(-11052,"zai");ht.Add(-11045,"zan");ht.Add(-11041,"zang"); 171 ht.Add(-11038,"zao");ht.Add(-11024,"ze");ht.Add(-11020,"zei"); 172 ht.Add(-11019,"zen");ht.Add(-11018,"zeng");ht.Add(-11014,"zha"); 173 ht.Add(-10838,"zhai");ht.Add(-10832,"zhan");ht.Add(-10815,"zhang"); 174 ht.Add(-10800,"zhao");ht.Add(-10790,"zhe");ht.Add(-10780,"zhen"); 175 ht.Add(-10764,"zheng");ht.Add(-10587,"zhi");ht.Add(-10544,"zhong"); 176 ht.Add(-10533,"zhou");ht.Add(-10519,"zhu");ht.Add(-10331,"zhua"); 177 ht.Add(-10329,"zhuai");ht.Add(-10328,"zhuan");ht.Add(-10322,"zhuang"); 178 ht.Add(-10315,"zhui");ht.Add(-10309,"zhun");ht.Add(-10307,"zhuo"); 179 ht.Add(-10296,"zi");ht.Add(-10281,"zong");ht.Add(-10274,"zou"); 180 ht.Add(-10270,"zu");ht.Add(-10262,"zuan");ht.Add(-10260,"zui"); 181 ht.Add(-10256,"zun");ht.Add(-10254,"zuo");ht.Add(-10247,"zz"); 182 return ht; 183}You can call it like this:[i]YourNamespace.GetSpell("博客园"),YourNamespace is your class's namespace.
I hope this helps.
相关文章推荐
- Code snippet of the day : Resizing ASP.NET Datagrid Controls in Edit mode at runtime
- Handle unmanaged code in managed c# with the help of using statement
- Book Contents Reviews Notes Errata Articles Talks Downloads Resources Code Formatter Cover of C# in Depth Order now (3rd edition) Implementing the Singleton Pattern in C#
- 获取本机已安装的软件列表C#/VB.NET(Get the list of installed software in local pc)
- Code snippet of the day : Convert Rich Text Into Plain Text.
- get the code of function in matlab
- Question 15: Which of the following statements describe the results of executing the code snippet below in C++?
- /*程序员面试宝典*/Which of the following statements describe the results of executing the code snippet below in C++?
- How can I get the IPv4 address of an interface in linux from C code ?
- (NOT CLEAR)Question 18: In the given C++ code snippet, which of the following statements correctly identify how Mon of enum DOW
- Code snippet of the day : Exporting DataGrid Data to Excel...
- Code snippet of the day : persist the scroll position of an ASP.NET page
- jqGrid中下拉框的实现(The realization of select in jqGrid via C#)
- OpenOffice.org Code Snippets--Get and modify the current selection in calc (in C++)
- How to get the number of pages in a Word Document
- the Byte length of Chinese Character in Oracle.
- ORA-30926: unable to get a stable set of rows in the source tables
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- How Would You Get the Count of an Array in C++?
- All-In-One Code Framework(AIO): 如何使用C#编写进程外的COM组件 (How to write an out-of-proc COM server in C#)