Using system;
Using system. Collections. Generic;
Using system. text;
Using system. Text. regularexpressions;
Namespace pycode
{
Public class autopycode
{
Private Static string [] lc_firstletter = NULL; // The start location code for storing different pronunciations of the first-level Chinese Character in the National Standard
Private Static string ls_secondsectable = string. Empty; // stores all the second-level Chinese characters of the national standard.
Private Static int [] li_secposvalue = NULL; // The start location code for storing different pronunciations of the first-level Chinese Character in the national standard.
Static autopycode ()
{
Li_secposvalue = new int [23] {1601,163 7, 1833,207 8, 2274,230 2, 2433,259 4, 2787,310 6, 3212,347 2, 3635,372 2, 3730,385 8, 4027,408 6, 4390,455 8, 4684,492 5, 5249 };
Lc_firstletter = new string [23] {"A", "B", "C", "D", "E", "F", "g", "H ", "J", "k", "L", "M", "n", "O", "P", "Q", "r", "S ", "T", "W", "X", "Y", "Z "};
Ls_secondsectable = "cjwgnspgcgne [Y [btyyzdxykygt [jnnjqmbsgzscyjsyy [pgkbzgy [ywjkgkljywkpjqhy [W [Ghost"
+ "Gkjfyxjwzltbncxjjjjtxdttsqzycdxxhgck [phffss [ybgxlppbyll [hlxs [ZM [J [wqjb"
+ "Listen [[dcsbbqbefsjyhxwgzkpylqbgldlcctnmayddkssngycsgxlyzaybnptsdkdylhgy"
+ "Mylcxpy [Rule"
+ "RunTime [ykldyxzpylgg [mtcfpajjzyljtyanjgbjplqgdzyqyaxbk"
+ "Ikejl"
+ "Kwhqasdknhcsganhdaashtcplcpqybsdmpjlpzjoqlcdhjjysprchn [callback"
+ "YD [fcxyhlxchyzjq [[metric [[ttxrycyxbyhcsmxjsznpwgpxx1_bgajcxly [dccwzocwkccsbnhcpdyznfcyytyc"
+ "Kxkybsqkkytqqxfcwchcykelzqbsqyjqcclmthsywhmktlkjlycxwheqqhtqh [PQ [quit"
+ "Examples [gdmycnqqwlqhjj [ywjzyejjdhpblqxtqkwhlchqxagtlxljxms"
+ "L [htzkzjecxjcjnmfby [using [yzgwkypsgxfzfc"
+ "Dkhjgxdlqfsgdslqwzkxtmhsbgzmjzrglyjbpmlmsxlzjqqhzyjczydjwbmyklddpmjegxyhylxhlqyqhkycwcjmyyxnatjhyccxzpcqlbzwwytwbqcmlpmyrjcccxf PZ"
+ "Nzzljplxxyztzlgdldcklyrzzgqtgjhhgjljaxfgfjzslcfdqzlclgjdjcsnzlljpjqdcclcjxmyzftsxgcgsbrzxjqqctzhgyqtjqqlzxjylylbcyamcstylpdjbyr eg"
+ "Yk"
+ "Y [distinct"
+ "Syyyfsxjc [dxxlhjhf [sxzqhfzmzcztqcxzxrttdjhnnyzqqmnqdmmg [unknown"
+ "Dsynsbrskmkmpcklgdbqtfzswtfgglyplljzhgj [Signature"
+ "Dig [djlslygk"
+ "Dzpzxjyyzlwcxszfgwyydlyhcljscmbjhblyzlycblydpdqysxqzbytdkyxjy [empty"
+ "Nmshrp [callback"
+ "Hqpdszglstjbckbxyqzjsgpsxqzqzrqtbdkyxzkhhgflbcsmdldgdzdblzyycxnncsybzbfglzzxswmsccmqnjqsbdqsjtxxmbltxzclzshzcxrqjgjylxzfjphymzq QY"
+ "Mongosm"
+ "Cjbtzkycwmytcsjjljcqlwzmalbxyfbpnlsfhtgjwejjxxglljstgshjqlzfkcgnnnszfdeqfhbsaqtgylbxmmygszldydqmjjrgbjtkgdhgkblqkbdmbylxwcxytty BK"
+ "Mrtjzxqjbhlmhmjjzmqasldcyxyqdlqcafywyxqhz ";
}
Private Static int32 sectorcode (char CHR)
{
Encoding ecode = encoding. getencoding ("gb18030 ");
Byte [] codebytes = ecode. getbytes (CHR. tostring ());
Return (INT) codebytes [0];
}
Private Static int32 positioncode (char CHR)
{
Encoding ecode = encoding. getencoding ("gb18030 ");
Byte [] codebytes = ecode. getbytes (CHR. tostring ());
Return (INT) codebytes [1];
}
Public static string getfirstletter (string Str)
{
String ls_ch = string. Empty; // temporary Unit
String ls_returnstr = string. Empty; // return string
Int li_sectorcode; // Chinese Character area code
Int li_positioncode; // Chinese character location code
Int li_secposcode; // Chinese character location code
Int li_offset; // second-level font offset
For (INT I = 0; I <Str. length; I ++) // process each character in STR in sequence
{
If (sectorcode (chinesestr [I])> = 65 & sectorcode (chinesestr [I]) <= 90) | // uppercase letter
(Sectorcode (chinesestr [I])> = 97 & sectorcode (chinesestr [I]) <= 122) // lowercase letter
{
Ls_returnstr = ls_returnstr + STR [I]. tostring (); // unchanged
}
Else if (sectorcode (STR [I])> = 128) // It is a Chinese character
{
Li_sectorcode = sectorcode (STR [I])-160; // area code
Li_positioncode = positioncode (STR [I])-160; // bit code
Li_secposcode = li_sectorcode * 100 + li_positioncode; // location code
If (li_secposcode> 1600 & li_secposcode <5590) // the first character
{
For (Int J = 23; j> = 1; j --) // find the initials
{
If (li_secposcode> = li_secposvalue [J-1])
{
Ls_returnstr = ls_returnstr + lc_firstletter [J-1];
Break;
}
}
}
Else
{
Li_offset = (li_sectorcode-56) * 94 + li_positioncode-1; // calculate the offset
If (li_offset> = 0 & li_offset <= 3007) // second-zone Chinese Character
{
Ls_returnstr = ls_returnstr + ls_secondsectable.substring (li_offset, 1); // extract the initials
}
}
}
}
Return ls_returnstr; // returns the initials.
}
}
}