網上關於Java中獲取漢字的拼音首字母的方法很多,但大多基於GB2312的漢字所屬編碼位置判斷方法,現有一種基於GBK編碼計算拼音首字母的方法,參考http://blog.csdn.net/z3h/article/details/6302890
筆者出的源碼是讀取文件默認編碼格式,默認是GBK,如果文件默認格式不是GBK將報錯,現在代碼讀取的格式默認設置為GBK,如下:
package com; import java.io.UnsupportedEncodingException; /** * 取得漢字拼音碼. * 支持GBK大字符集. * @author Zhao Honghui * @version 1.0 */ public class GetPy { private static final String GB_2312 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbp" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbpbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "pbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb" + "bbbbbbbbbbbbbbbbbbbbcccccccccccccccccccccccccccccc" + "ccccccccccccccccccccccccccccccccccczcccccccccccccc" + "ccccccccccccccccccccccccccccccccccccsccccccccccccc" + "cccccccccccccccccccccccccccccccccccccccccczccccccc" + "cccccccccccccccccccccccccccccccccccccccccccccccccc" + "cccddddddddddddddddddddddddddddddddddddddddddddddd" + "dddddddddddddddddddddzdddddddddddddddddddddddddddd" + "dddddddddddddddddddddddddddddddtdddddddddddddddddd" + "dddddddddddddddddddddddddddddddddddddeeeeeeeeeeeee" + "eeeeeeeeefffffffffffffffffffffffffffffffffffffffff" + "ffffffffffffffffffffffffffffffffffffffffffffffffff" + "fffffffffffffpffffffffffffffffffffgggggggggggggggg" + "ggggggggggggggggggghggggggggggggghgggggggggggggggg" + "gggggggggggggggggggggggggggggggggggggggggggggggggg" + "ggggggggggggggggggggggggggggggggggggggghhhhhhhhhhh" + "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhmhhhhhhhhhhh" + "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" + "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" + "hhhhhhhhhhhhhhhhhhhhjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjjjjjjjjkjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjyjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj" + "jjjjjjjjjjjjjjjkkkgkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkh" + "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" + "kkkkkkkkkkkkkkklllllllllllllllllllllllllllllllllll" + "llllllllllllllllllllllllllllllllllllllllllllllllll" + "llllllllllllllllllllllllllllllllllllllllllllllllll" + "llllllllllllllllllllllllllllllllllllllllllllllllll" + "llllllllllllllllllllllllllllllllllllllllllllllllll" + "lllllllllllllmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm" + "mmmmmmmmmmmmmmnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn" + "nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnooooo" + "oooppppppppppppppppppppppppppppppppppppppppppppppp" + "pppppppppppppppppppppppppppppppppppppppppppppppppp" + "ppppppppppppppppppppppppbqqqqqqqqqqqqqqqqqqqqqqqqq" + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq" + "qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqrrrrrrrrrrrrrrrrrr" + "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrsssssssss" + "ssssssssssssssssssssssssssssssssssssssssssssssssss" + "ssssssssssssssssssssssssssssssssssssssssssssssssss" + "ssssssssssssssssssssssssssssssssssssssssssssssssss" + "ssssssssssssssssssssssssssssssssssssssssssssssssss" + "sssssssssssssssssssssssssssssssssssssssssssssssssx" + "sssssssssssssssssssssssssssttttttttttttttttttttttt" + "tttttttttttttttttttttttttttttttttttttttttttttttttt" + "tttttttttttttttttttttttttttttttttttttttttttttttttt" + "tttttttttttttttttttttttttttttttttwwwwwwwwwwwwwwwww" + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" + "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww" + "wwwxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxsx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxjxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + "xxxxxhxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxcxxxxxxxxx" + "xxxxxxxxxxxxxxxxxxxxxxxxxxyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyxyyyyyyyyyyyyyyyyyyyyyyyyy" + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzczzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + "zzzzz cjwgnspgcgnesypbtyyzdxykygtdjnnjqmbsjzsc" + "yjsyyfpgkbzgylywjkgkljywkpjqhytwddzlsymrypywwcckzn" + "kyygttngjnykkzytcjnmcylqlypysfqrpzslwbtgkjfyxjwzlt" + "bncxjjjjtxdttsqzycdxxhgckbphffsswybgmxlpbylllhlxst" + "zmyjhsojnghdzqyklgjhsgqzhxqgkxzzwyscscjxyeyxadzpmd" + "ssmzjzqjyzcdjzwqjbyzbjgznzcpwhwxhqkmwfbpbydtjzzkxx" + "ylygxfptyjyyzpszlfchmqshgmxxsxjyqdcsbbqbefsjyhxwgz" + "kpylqbgldlcdtnmaeddkssngycsgxlyzaypnptsdkdylhgymyl" + "cxpycjndqjwxqxfyyfjlejpzrxccqwqqsbzkymgplbmjrqcfln" + "ymyqmtqyrbcjthztqfrxqhxmqjcjlyxgjmshzkbswyemyltxfs" + "ydsglycjqxsjnqbsctyhbftdcyjdjyyghqfsxwckqkxebptlpx" + "jzsrmebwhjlpjslyysmdxlclqkxlhxjrzjmfqhxhwywsbhtrxx" + "glhqhfnmgykldyxzpylggtmtcfpnjjzyljtyanjgbjplqgszyq" + "yaxbkysecjsznslyzhzxlzcghpxzhznytdsbcjkdlzayfmytle" + "bbgqyzkggldndnyskjshdlyxbcgyxypkdjmmzngmmclgezszxz" + "jfznmlzzthcsydbdllscddnlkjykjsycjlkwhqasdknhcsgaeh" + "daashtcplcpqybsdmpjlpzjoqlcdhjxysprchnwjnlhlyyqyhw" + "zptczgwwmzffjqqqqyxaclbhkdjxdgmmydqxzllsygxgkjrywz" + "wyclzmssjzldbydcpcxyhlxchyzjqsfqagmnyxpfrkssbjlyxy" + "syglnscmhcwwmnzjjlxxhchsyzsttxrycyxbyhcsmxjsznpwgp" + "xxtaybgajcxlysdccwzocwkccsbnhcpdyznfcyytyckxkybsqk" + "kytqqxfcwchcykelzqbsqyjqcclmthsywhmktlkjlycxwheqqh" + "tqkjpqsqscfymmdmgbwhwlgsllystlmlxpthmjhwljzyhzjxht" + "xjlhxrswlwzjcbxmhzqxsdzpsgfcsglsxymqshxpjxwmyqksmy" + "plrthbxftpmhyxlchlhlzylxgsssstclsldclrpbhzhxyyfhbb" + "gdmycnqqwlqhjjzywjzyejjdhpblqxtqkwhlchqxagtlxljxms" + "ljhtzkzjecxjcjnmfbycsfywybjzgnysdzsqyrsljpclpwxsdw" + "ejbjcbcnaytwgmpapclyqpclzxsbnmsggfnzjjbzsfzyndxhpl" + "qkzczwalsbccjxjyzgwkypsgxfzfcdkhjgxtlqfsgdslqwzkxt" + "mhsbgzmjzrglyjbpmlmsxlzjqzhzyjczydjwfmjklddpmjegxy" + "hylxhlqyqhkycwcjmyyxnatjhyccxzpcqlbzwwytwsqcmlpmyr" + "jcccxfpznzzljplxxyztzlgdltcklyrzzgqtkjhhgjljaxfgfj" + "zslcfdqzlclgjdjcsnzlljpjqdcclcjxmyzftsxgcgsbrzxjqq" + "ctzhgyqtjqqlzxjylylncyamcstylpdjbyregklzyzhlyszqlz" + "nwczcllwjqjjjkdgjzolbbzppglghtgzxyjhzmycnqsycyhbhg" + "xkamtxyxnbskyzzgjzlqjtfcjxdygjqjjpmgwgjjjpkqsbgbmm" + "cjssclpqpdxcdyykyfcjddyygywrhjrtgznyqldkljszzgzqzj" + "gdykshpzmtlcpwnjyfyzdjcnmwescyglbtzcgmssllyxqsxxbs" + "jsbbsgghfjlypmzjnlyywdqshzxtyywhmcyhywdbxbtlmsyyyf" + "sxjchtxxlhjhfssxzqhfzmzcztqcxzxrttdjhnnyzqqmtqdmmz" + " ytxmjgdxcdyzbffallztdltfxmxqzdngwqdbdczjdxbzgsqqd" + "djcmbkzffxmkdmdsyyszcmljdsynsprskmkmpcklgdbqtfzswt" + "fgglyplljzhgjjgypzltcsmcnbtjbqfkdhpyzgkpbbymtdssxt" + "bnpdkleycjnyddykzddhqhsdzsctarlltkzlgecllkjlqjaqnb" + "dkkghpjxzqksecshalqfmmgjnlyjbbtmlyzxdxjpldlpcqdhzy" + "cbzsczbzmsljflkrzjsnfrgjhxpdhyjybzgdlqcsezgxlblhyx" + "twmabchecmwyjyzlljjyhlgbdjlslygkdzpzxjyyzlwcxszfgw" + "yydlyhcljscmbjhblyzlycblydpdqysxqzbytdkyxlyycnrjmp" + "dqgklcljbcxbjddbblblczqrppxjcjlzcshltoljnmdddlngka" + "thqhjhykheznmshrphqqjchgmfprxhjgdychgklyrzqlcyqjnz" + "sqtkqjymszxwlcfqqqxyfggyptqwlmcrnfkkfsyylybmqammmy" + "xctpshcptxxzzsmphpshmclmldqfyqxszyjdjjzzhqpdszglst" + "jbckbxyqzjsgpsxqzqzrqtbdkwxzkhhgflbcsmdldgdzdblzyy" + "cxnncsybzbfglzzxswmsccmqnjqsbdqsjtxxmbltxcclzshzcx" + "rqjgjylxzfjphymzqqydfqjqlzznzjcdgzygztxmzysctlkpht" + "xhtlbjxjlxscdqxcbbtjfqzfsltjbtkqbxxjjljchczdbzjdcz" + "jdcprnpqcjpfczlclzxzdmxmphjsgzgszzqlylwtjpfsyaxmcj" + "btzyycwmytzsjjlqcqlwzmalbxyfbpnlsfhtgjwejjxxglljst" + "gshjqlzfkcgnndszfdeqfhbsaqtgylbxmmygszldydqmjjrgbj" + "tkgdhgkblqkbdmbylxwcxyttybkmrtjzxqjbhlmhmjjzmqasld" + "cyxyqdlqcafywyxqhz"; private static final String GBK_3 = "ksxsm sdqlybjjjgczbjfya jhphsyzgj sn xy ng" + " lggllyjds yssgyqyd xjyydldwjjwbbftbxthhbczcrfm" + "qwyfcwdzpyddwyxjajpsfnzyjxxxcxnnxxzzbpysyzhmzbqbzc" + "ycbxqsbhhxgfmbhhgqcxsthlygymxalelccxzrcsd njjtzzcl" + "jdtstbnxtyxsgkwyflhjqspxmxxdc lshxjbcfybyxhczbjyzl" + "wlcz gtsmtzxpqglsjfzzlslhdzbwjncjysnycqrzcwybtyftw" + "ecskdcbxhyzqyyxzcffzmjyxxsdcztbzjwszsxyrnygmdthjxs" + "qqccsbxrytsyfbjzgclyzzbszyzqscjhzqydxlbpjllmqxtydz" + "sqjtzplcgqtzwjbhcjdyfxjelbgxxmyjjqfzasyjnsydk jcjs" + "zcbatdclnjqmwnqncllkbybzzsyhjqltwlccxthllzntylnzxd" + "dtcenjyskkfksdkghwnlsjt jymrymzjgjmzgxykymsmjklfxm" + "tghpfmqjsmtgjqdgyalcmzcsdjlxdffjc f ffkgpkhrcjqcj" + "dwjlfqdmlzbjjscgckdejcjdlzyckscclfcq czgpdqzjj hdd" + "wgsjdkccctllpskghzzljlgjgjjtjjjzczmlzyjkxzyzmljkyw" + "xmkjlkjgmclykjqlblkmdxwyxysllpsjqjqxyqfjtjdmxxllcr" + "qyjb xgg pjygegdjgnjyjkhqfqzkhyghdgllsdjjxkyoxnzsx" + "wwxdcskxxjyqscsqkjexsyzhydz ptqyzmtstzfsyldqagylcq" + "lyyyhlrq ldhsssadsjbrszxsjyrcgqc hmmxzdyohycqgphhy" + "nxrhgjlgwqwjhcstwasjpmmrdsztxyqpzxyhyqxtpbfyhhdwzb" + "txhqeexzxxkstexgltxydn hyktmzhxlplbmlsfhyyggbhyqt" + "xwlqczydqdq gd lls zwjqwqajnytlxanzdecxzwwsgqqdyzt" + "chyqzlxygzglydqtjtadyzzcwyzymhyhyjzwsxhzylyskqysbc" + "yw xjzgtyxqsyhxmchrwjpwxzlwjs sgnqbalzzmtjcjktsax" + "ljhhgoxzcpdmhgtysjxhmrlxjkxhmqxctxwzbkhzccdytxqhlx" + "hyx syydz znhxqyaygypdhdd pyzndltwxydpzjjcxmtlhbyn" + "yymhzllhnmylllmdcppxmxdkycydltxchhznaclcclylzsxzjn" + "zln lhyntkyjpychegttgqrgtgyhhlgcwyqkpyyyttttlhylly" + "ttplkyzqqzdq nmjzxyqmktfbjdjjdxbtqzgtsyflqgxblzfh" + " zadpmjhlccyhdzfgydgcyxs hd d axxbpbyyaxcqffqyjxdl" + "jjzl bjydyqszwjlzkcdtctbkdyzdqjnkknjgyeglfykasntch" + "blwzbymjnygzyheyfjmctyfzjjhgck lxhdwxxjkyykssmwctq" + "zlpbzdtwzxzag kwxl lspbclloqmmzslbczzkdcz xgqqdcyt" + "zqwzqssfpktfqdcdshdtdwfhtdy jaqqkybdjyxtlj drqxxxa" + "ydrjlklytwhllrllcxylbw z zzhkhxksmdsyyjpzbsqlcxxn" + "xwmdq gqmmczjgttybhyjbetpjxdqhkzbhfdxkawtwajldyjsf" + "hblddqjncxfjhdfjjwzpkzypcyzynxff ydbzznytxzembsehx" + "fzmbflzrsymzjrdjgxhjgjjnzzxhgxhymlpeyyxtgqshxssxmf" + "mkcctxnypszhzptxwywxyysljsqxzdleelmcpjclxsqhfwwtff" + "tnqjjjdxhwlyznflnkyyjldx hdynrjtywtrmdrqhwqcmfjdyz" + "hmyyxjwzqtxtlmrspwwchjb xygcyyrrlmpymkszyjrmysntpl" + "nbpyyxmykyngjzznlzhhanmpgwjdzmxxmllhgdzxyhxkrycjmf" + "fxyhjfssqlxxndyca nmtcjcyprrnytyqym sxndlylyljnlxy" + "shqmllyzljzxstyzsmcqynzlxbnnylrqtryyjzzhsytxcqgxzs" + "shmkczyqhzjnbh qsnjnzybknlqhznswxkhjyybqlbfl p bkq" + "zxsddjmessmlxxkwnmwwwydkzggtggxbjtdszxnxwmlptfxlcx" + "jjljzxnwxlyhhlrwhsc ybyawjjcwqqjzzyjgxpltzftpakqpt" + "lc xtx hklefdleegqymsawhmljtwyqlyjeybqfnlyxrdsctg" + "gxyyn kyqctlhjlmkkcgygllldzydhzwpjzkdyzzhyyfqytyzs" + "ezzlymhjhtwyzlkyywzcskqqtdxwctyjklwqbdqyncs szjlkc" + "dcdtlzzacqqzzddxyplxzbqjylzllqdzqgyjyjsyxnyyynyjxk" + "xdazwrdljyyynjlxllhxjcykynqcclddnyyykyhhjcl pb qzz" + "yjxj fzdnfpzhddwfmyypqjrssqzsqdgpzjwdsjdhzxwybp gp" + "tmjthzsbgzmbjczwbbzmqcfmbdmcjxljbgjtz mqdyxjzyctyz" + "tzxtgkmybbcljssqymscx jeglxszbqjjlyxlyctsxmcwfa kb" + "qllljyxtyltxdphnhfqyzyes sdhwdjbsztfd czyqsyjdzjqp" + "bs j fbkjbxtkqhmkwjjlhhyyyyywyycdypczyjzwdlfwxwzzj" + "cxcdjzczlxjjtxbfwpxzptdzbccyhmlxbqlrtgrhqtlf mwwjx" + "jwcysctzqhxwxkjybmpkbnzhqcdtyfxbyxcbhxpsxt m sxlhk" + "mzxydhwxxshqhcyxglcsqypdh my ypyyykzljqtbqxmyhcwll" + "cyl ewcdcmlggqktlxkgndgzyjjlyhqdtnchxwszjydnytcqcb" + "hztbxwgwbxhmyqsycmqkaqyncs qhysqyshjgjcnxkzycxsbxx" + "hyylstyxtymgcpmgcccccmztasgqzjlosqylstmqsqdzljqqyp" + "lcycztcqqpbqjclpkhz yyxxdtddsjcxffllxmlwcjcxtspyxn" + "dtjsjwxqqjskyylsjhaykxcyydmamdqmlmczncybzkkyflmcsc" + "lhxrcjjgslnmtjzzygjddzjzk qgjyyxzxxqhheytmdsyyyqlf" + " zzdywhscyqwdrxqjyazzzdywbjwhyqszywnp azjbznbyzzy" + "hnscpjmqcy zpnqtbzjkqqhngccxchbzkddnzhjdrlzlsjljyx" + "ytbgtcsqmnjpjsrxcfjqhtpzsyjwbzzzlstbwwqsmmfdwjyzct" + "bwzwqcslqgdhqsqlyzlgyxydcbtzkpj gm pnjkyjynhpwsnsz" + "zxybyhyzjqjtllcjthgdxxqcbywbwzggqrqzssnpkydznxqxjm" + "y dstzplthzwxwqtzenqzw ksscsjccgptcslccgllzxczqthn" + "jgyqznmckcstjskbjygqjpldxrgzyxcxhgdnlzwjjctsbcjxbf" + "zzpqdhjtywjynlzzpcjdsqjkdxyajyemmjtdljyryynhjbngzj" + "kmjxltbsllrzylcscnxjllhyllqqqlxymswcxsljmc zlnsdwt" + "jllggjxkyhbpdkmmscsgxjcsdybxdndqykjjtxdygmzzdzslo " + "yjsjzdlbtxxxqqjzlbylwsjjyjtdzqqzzzzjlzcdzjhpl qplf" + "fjzysj zfpfzksyjjhxttdxcysmmzcwbbjshfjxfqhyzfsjybx" + "pzlhmbxhzxfywdab lktshxkxjjzthgxh jxkzxszzwhwtzzzs" + "nxqzyawlcwxfxyyhxmyyswqmnlycyspjkhwcqhyljmzxhmcnzh" + "hxcltjplxyjhdyylttxfszhyxxsjbjyayrmlckd yhlrlllsty" + "zyyhscszqxkyqfpflk ntljmmtqyzwtlll s rbdmlqjbcc qy" + "wxfzrzdmcyggzjm mxyfdxc shxncsyjjmpafyfnhyzxyezy " + "sdl zztxgfmyyysnbdnlhpfzdcyfssssn zzdgpafbdbzszbsg" + "cyjlm z yxqcyxzlckbrbrbzcycjzeeyfgzlyzsfrtkqsxdcm" + "z jl xscbykjbbrxllfqwjhyqylpzdxczybdhzrbjhwnjtjxl" + "kcfssdqyjkzcwjl b tzlltlqblcqqccdfpphczlyygjdgwcf" + "czqyyyqyrqzslszfcqnwlhjcjjczkypzzbpdc jgx gdz f" + "gpsysdfwwjzjyxyyjyhwpbygxrylybhkjksftzmmkhtyysyyzp" + "yqydywmtjjrhl tw bjycfnmgjtysyzmsjyjhhqmyrszwtr" + "tzsskx gqgsptgcznjjcxmxgzt ydjz lsdglhyqgggthszpyj" + "hhgnygkggmdzylczlxqstgzslllmlcskbljzzsmmytpzsqjcj " + " zxzzcpshkzsxcdfmwrllqxrfzlysdctmxjthjntnrtzfqyhqg" + "llg sjdjj tqjlnyhszxcgjzypfhdjspcczhjjjzjqdyb ss" + "lyttmqtbhjqnnygjyrqyqmzgcjkpd gmyzhqllsllclmholzgd" + "yyfzsljc zlylzqjeshnylljxgjxlyjyyyxnbzljsszcqqzjyl" + "lzldj llzllbnyl hxxccqkyjxxxklkseccqkkkcgyyxywtqoh" + "thxpyxx hcyeychbbjqcs szs lzylgezwmysx jqqsqyyycmd" + "zywctjsycjkcddjlbdjjzqysqqxxhqjohdyxgmajpchcpljsmt" + "xerxjqd pjdbsmsstktssmmtrzszmldj rn sqxqydyyzbdsln" + "fgpzmdycwfdtmypqwytjzzqjjrjhqbhzpjhnxxyydyhhnmfcpb" + "zpzzlzfmztzmyftskyjyjzhbzzygh pzcscsjssxfjgdyzyhzc" + "whcsexfqzywklytmlymqpxxskqjpxzhmhqyjs cjlqwhmybdhy" + "ylhlglcfytlxcjscpjskphjrtxteylssls yhxscznwtdwjslh" + "tqdjhgydphcqfzljlzptynlmjllqyshhylqqzypbywrfy js y" + "p yrhjnqtfwtwrchygmm yyhsmzhngcelqqmtcwcmpxjjfyysx" + "ztybmstsyjdtjqtlhynpyqzlcxznzmylflwby jgsylymzctdw" + "gszslmwzwwqzsayysssapxwcmgxhxdzyjgsjhygscyyxhbbzjk" + "ssmalxycfygmqyjycxjlljgczgqjcczotyxmtthlwtgfzkpzcx" + "kjycxctjcyh xsgckxzpsjpxhjwpjgsqxxsdmrszzyzwsykyzs" + "hbcsplwsscjhjlchhylhfhhxjsx lnylsdhzxysxlwzyhcldyh" + "zmdyspjtqznwqpsswctst zlmssmnyymjqjzwtyydchqlxkwbg" + "qybkfc jdlzllyylszydwhxpsbcmljscgbhxlqrljxysdwxzsl" + "df hlslymjljylyjcdrjlfsyjfnllcqyqfjy szlylmstdjcyh" + "zllnwlxxygyygxxhhzzxczqzfnwpypkpypmlgxgg dxzzkzfbx" + "xlzptytswhzyxhqhxxxywzyswdmzkxhzphgchj lfjxptzthly" + "xcrhxshxkjxxzqdcqyl jlkhtxcwhjfwcfpqryqxyqy gpggsc" + "sxngkchkzxhflxjbyzwtsxxncyjjmwzjqrhfqsyljzgynslgtc" + "ybyxxwyhhxynsqymlywgyqbbzljlpsytjzhyzwlrorjkczjxxy" + "xchdyxyxxjddsqfxyltsfxlmtyjmjjyyxltcxqzqhzlyyxzh n" + "lrhxjcdyhlbrlmrllaxksllljlxxxlycry lccgjcmtlzllyzz" + "pcw jyzeckzdqyqpcjcyzmbbcydcnltrmfgyqbsygmdqqzmkql" + "pgtbqcjfkjcxbljmswmdt ldlppbxcwkcbjczhkphyyhzkzmp" + "jysylpnyyxdb"; private static final String GBK_4 = "kxxmzjxsttdzxxbzyshjpfxpqbyljqkyzzzwl zgfwyctjxjpy" + "yspmsmydyshqy zchmjmcagcfbbhplxtyqx djgxdhkxxnbhrm" + "lnjsltsmrnlxqjyzlsqglbhdcgyqyyhwfjybbyjyjjdpqyapfx" + "cgjscrssyz lbzjjjlgxzyxyxsqkxbxxgcxpld wetdwwcjmbt" + "xchxyxxfxllj fwdpzsmylmwytcbcecblgdbqzqfjdjhymcxtx" + "drmjwrh xcjzylqdyhlsrsywwzjymtllltqcjzbtckzcyqjzqa" + "lmyhwwdxzxqdllqsgjfjljhjazdjgtkhsstcyjfpszlxzxrwgl" + "dlzr lzqtgslllllyxxqgdzybphl x bpfd hy jcc dmzpp" + "z cyqxldozlwdwyythcqsccrsslfzfp qmbjxlmyfgjb m jwd" + "n mmjtgbdzlp hsymjyl hdzjcctlcl ljcpddqdsznbgzxxcx" + "qycbzxzfzfjsnttjyhtcmjxtmxspdsypzgmljtycbmdkycsz z" + "yfyctgwhkyjxgyclndzscyzssdllqflqllxfdyhxggnywyllsd" + "lbbjcyjzmlhl xyyytdlllb b bqjzmpclmjpgehbcqax hhhz" + "chxyhjaxhlphjgpqqzgjjzzgzdqybzhhbwyffqdlzljxjpalxz" + "daglgwqyxxxfmmsypfmxsyzyshdzkxsmmzzsdnzcfp ltzdnmx" + "zymzmmxhhczjemxxksthwlsqlzllsjphlgzyhmxxhgzcjmhxtx" + "fwkmwkdthmfzzydkmsclcmghsxpslcxyxmkxyah jzmcsnxyym" + "mpmlgxmhlmlqmxtkzqyszjshyzjzybdqzwzqkdjlfmekzjpezs" + "wjmzyltemznplplbpykkqzkeqlwayyplhhaq jkqclhyxxmlyc" + "cyskg lcnszkyzkcqzqljpmzhxlywqlnrydtykwszdxddntqd" + "fqqmgseltthpwtxxlwydlzyzcqqpllkcc ylbqqczcljslzjxd" + "dbzqdljxzqjyzqkzljcyqdypp pqykjyrpcbymxkllzllfqpyl" + "llmsglcyrytmxyzfdzrysyztfmsmcl ywzgxzggsjsgkdtggzl" + "ldzbzhyyzhzywxyzymsdbzyjgtsmtfxqyjssdgslnndlyzzlrx" + "trznzxnqfmyzjzykbpnlypblnzz jhtzkgyzzrdznfgxskgjtt" + "yllgzzbjzklplzylxyxbjfpnjzzxcdxzyxzggrs jksmzjlsjy" + "wq yhqjxpjzt lsnshrnypzt wchklpszlcyysjylybbwzpdwg" + "cyxckdzxsgzwwyqyytctdllxwkczkkcclgcqqdzlqcsfqchqhs" + "fmqzlnbbshzdysjqplzcd cwjkjlpcmz jsqyzyhcpydsdzngq" + "mbsflnffgfsm q lgqcyybkjsrjhzldcftlljgjhtxzcszztjg" + "gkyoxblzppgtgyjdhz zzllqfzgqjzczbxbsxpxhyyclwdqjjx" + "mfdfzhqqmqg yhtycrznqxgpdzcszcljbhbzcyzzppyzzsgyhc" + "kpzjljnsc sllxb mstldfjmkdjslxlsz p pgjllydszgql l" + "kyyhzttnt tzzbsz ztlljtyyll llqyzqlbdzlslyyzyfszs" + "nhnc bbwsk rbc zm gjmzlshtslzbl q xflyljqbzg st" + "bmzjlxfnb xjztsfjmssnxlkbhsjxtnlzdntljjgzjyjczxygy" + "hwrwqnztn fjszpzshzjfyrdjfcjzbfzqchzxfxsbzqlzsgyft" + "zdcszxzjbqmszkjrhyjzckmjkhchgtxkjqalxbxfjtrtylxjhd" + "tsjx j jjzmzlcqsbtxhqgxtxxhxftsdkfjhzxjfj zcdlllt" + "qsqzqwqxswtwgwbccgzllqzbclmqqtzhzxzxljfrmyzflxys x" + "xjk xrmqdzdmmyxbsqbhgcmwfwtgmxlzpyytgzyccddyzxs g " + "yjyznbgpzjcqswxcjrtfycgrhztxszzt cbfclsyxzlzqmzlmp" + " lxzjxslbysmqhxxz rxsqzzzsslyflczjrcrxhhzxq dshjsj" + "jhqcxjbcynsssrjbqlpxqpymlxzkyxlxcjlcycxxzzlxlll hr" + "zzdxytyxcxff bpxdgygztcqwyltlswwsgzjmmgtjfsgzyafsm" + "lpfcwbjcljmzlpjjlmdyyyfbygyzgyzyrqqhxy kxygy fsfsl" + "nqhcfhccfxblplzyxxxkhhxshjzscxczwhhhplqalpqahxdlgg" + "gdrndtpyqjjcljzljlhyhyqydhz zczywteyzxhsl jbdgwxpc" + " tjckllwkllcsstknzdnqnttlzsszyqkcgbhcrrychfpfyrwq" + "pxxkdbbbqtzkznpcfxmqkcypzxehzkctcmxxmx nwwxjyhlstm" + "csqdjcxctcnd p lccjlsblplqcdnndscjdpgwmrzclodansyz" + "rdwjjdbcxwstszyljpxloclgpcjfzljyl c cnlckxtpzjwcyx" + "wfzdknjcjlltqcbxnw xbxklylhzlqzllzxwjljjjgcmngjdzx" + "txcxyxjjxsjtstp ghtxdfptffllxqpk fzflylybqjhzbmddb" + "cycld tddqlyjjwqllcsjpyyclttjpycmgyxzhsztwqwrfzhjg" + "azmrhcyy ptdlybyznbbxyxhzddnh msgbwfzzjcyxllrzcyxz" + "lwjgcggnycpmzqzhfgtcjeaqcpjcs dczdwldfrypysccwbxgz" + "mzztqscpxxjcjychcjwsnxxwjn mt mcdqdcllwnk zgglcczm" + "lbqjqdsjzzghqywbzjlttdhhcchflsjyscgc zjbypbpdqkxwy" + "yflxncwcxbmaykkjwzzzrxy yqjfljphhhytzqmhsgzqwbwjdy" + "sqzxslzyymyszg x hysyscsyznlqyljxcxtlwdqzpcycyppnx" + "fyrcmsmslxglgctlxzgz g tc dsllyxmtzalcpxjtjwtcyyjb" + "lbzlqmylxpghdlssdhbdcsxhamlzpjmcnhjysygchskqmc lwj" + "xsmocdrlyqzhjmyby lyetfjfrfksyxftwdsxxlysjslyxsnxy" + "yxhahhjzxwmljcsqlkydztzsxfdxgzjksxybdpwnzwpczczeny" + "cxqfjykbdmljqq lxslyxxylljdzbsmhpsttqqwlhogyblzzal" + "xqlzerrqlstmypyxjjxqsjpbryxyjlxyqylthylymlkljt llh" + "fzwkhljlhlj klj tlqxylmbtxchxcfxlhhhjbyzzkbxsdqc j" + "zsyhzxfebcqwyyjqtzyqhqqzmwffhfrbntpcjlfzgppxdbbztg" + " gchmfly xlxpqsywmngqlxjqjtcbhxspxlbyyjddhsjqyjxll" + "dtkhhbfwdysqrnwldebzwcydljtmxmjsxyrwfymwrxxysztzzt" + "ymldq xlyq jtscxwlprjwxhyphydnxhgmywytzcs tsdlwdcq" + "pyclqyjwxwzzmylclmxcmzsqtzpjqblgxjzfljjytjnxmcxs c" + "dl dyjdqcxsqyclzxzzxmxqrjhzjphfljlmlqnldxzlllfypny" + "ysxcqqcmjzzhnpzmekmxkyqlxstxxhwdcwdzgyyfpjzdyzjzx " + "rzjchrtlpyzbsjhxzypbdfgzzrytngxcqy b cckrjjbjerzgy" + " xknsjkljsjzljybzsqlbcktylccclpfyadzyqgk tsfc xdk" + "dyxyfttyh wtghrynjsbsnyjhkllslydxxwbcjsbbpjzjcjdz" + "bfxxbrjlaygcsndcdszblpz dwsbxbcllxxlzdjzsjy lyxfff" + "bhjjxgbygjpmmmpssdzjmtlyzjxswxtyledqpjmygqzjgdblqj" + "wjqllsdgytqjczcjdzxqgsgjhqxnqlzbxsgzhcxy ljxyxydfq" + "qjjfxdhctxjyrxysqtjxyebyyssyxjxncyzxfxmsyszxy schs" + "hxzzzgzcgfjdltynpzgyjyztyqzpbxcbdztzc zyxxyhhsqxsh" + "dhgqhjhgxwsztmmlhyxgcbtclzkkwjzrclekxtdbcykqqsayxc" + "jxwwgsbhjyzs csjkqcxswxfltynytpzc czjqtzwjqdzzzqz" + "ljjxlsbhpyxxpsxshheztxfptjqyzzxhyaxncfzyyhxgnxmywx" + "tcspdhhgymxmxqcxtsbcqsjyxxtyyly pclmmszmjzzllcogxz" + "aajzyhjmzxhdxzsxzdzxleyjjzjbhzmzzzqtzpsxztdsxjjlny" + "azhhyysrnqdthzhayjyjhdzjzlsw cltbzyecwcycrylcxnhzy" + "dzydtrxxbzsxqhxjhhlxxlhdlqfdbsxfzzyychtyyjbhecjkgj" + "fxhzjfxhwhdzfyapnpgnymshk mamnbyjtmxyjcthjbzyfcgty" + "hwphftwzzezsbzegpbmtskftycmhbllhgpzjxzjgzjyxzsbbqs" + "czzlzccstpgxmjsftcczjz djxcybzlfcjsyzfgszlybcwzzby" + "zdzypswyjgxzbdsysxlgzybzfyxxxccxtzlsqyxzjqdcztdxzj" + "jqcgxtdgscxzsyjjqcc ldqztqchqqjzyezwkjcfypqtynlmkc" + "qzqzbqnyjddzqzxdpzjcdjstcjnxbcmsjqmjqwwjqnjnlllwqc" + "qqdzpzydcydzcttf znztqzdtjlzbclltdsxkjzqdpzlzntjxz" + "bcjltqjldgdbbjqdcjwynzyzcdwllxwlrxntqqczxkjld tdgl" + " lajjkly kqll dz td ycggjyxdxfrskstqdenqmrkq hgkd" + "ldazfkypbggpzrebzzykyqspegjjglkqzzzslysywqzwfqzylz" + "zlzhwcgkyp qgnpgblplrrjyxcccyyhsbzfybnyytgzxylxczw" + "h zjzblfflgskhyjzeyjhlplllldzlyczblcybbxbcbpnnzc r" + " sycgyy qzwtzdxtedcnzzzty hdynyjlxdjyqdjszwlsh lbc" + "zpyzjyctdyntsyctszyyegdw ycxtscysmgzsccsdslccrqxyy" + "elsm xztebblyylltqsyrxfkbxsychbjbwkgskhhjh xgnlycd" + "lfyljgbxqxqqzzplnypxjyqymrbsyyhkxxstmxrczzywxyhymc" + "l lzhqwqxdbxbzwzmldmyskfmklzcyqyczqxzlyyzmddz ftqp" + "czcyypzhzllytztzxdtqcy ksccyyazjpcylzyjtfnyyynrs y" + "lmmnxjsmyb sljqyldzdpqbzzblfndsqkczfywhgqmrdsxycyt" + "xnq jpyjbfcjdyzfbrxejdgyqbsrmnfyyqpghyjdyzxgr htk " + "leq zntsmpklbsgbpyszbydjzsstjzytxzphsszsbzczptqfzm" + "yflypybbjgxzmxxdjmtsyskkbzxhjcelbsmjyjzcxt mljshrz" + "zslxjqpyzxmkygxxjcljprmyygadyskqs dhrzkqxzyztcghyt" + "lmljxybsyctbhjhjfcwzsxwwtkzlxqshlyjzjxe mplprcglt " + "zztlnjcyjgdtclklpllqpjmzbapxyzlkktgdwczzbnzdtdyqzj" + "yjgmctxltgcszlmlhbglk njhdxphlfmkyd lgxdtwzfrjejz" + "tzhydxykshwfzcqshknqqhtzhxmjdjskhxzjzbzzxympagjmst" + "bxlskyynwrtsqlscbpspsgzwyhtlksssw hzzlyytnxjgmjszs" + "xfwnlsoztxgxlsmmlbwldszylkqcqctmycfjbslxclzzclxxks" + "bjqclhjpsqplsxxckslnhpsfqqytxy jzlqldtzqjzdyydjnzp" + "d cdskjfsljhylzsqzlbtxxdgtqbdyazxdzhzjnhhqbyknxjjq" + "czmlljzkspldsclbblzkleljlbq ycxjxgcnlcqplzlznjtzlx" + "yxpxmyzxwyczyhzbtrblxlcczjadjlmmmsssmybhb kkbhrsxx" + "jmxsdynzpelbbrhwghfchgm klltsjyycqltskywyyhywxbxq" + "ywbawykqldq tmtkhqcgdqktgpkxhcpthtwthkshthlxyzyyda" + "spkyzpceqdltbdssegyjq xcwxssbz dfydlyjcls yzyexcyy" + "sdwnzajgyhywtjdaxysrltdpsyxfnejdy lxllqzyqqhgjhzyc" + "shwshczyjxllnxzjjn fxmfpycyawddhdmczlqzhzyztldywll" + "hymmylmbwwkxydtyldjpyw xjwmllsafdllyflb bqtzcqlj" + "tfmbthydcqrddwr qnysnmzbyytbjhp ygtjahg tbstxkbtzb" + "kldbeqqhqmjdyttxpgbktlgqxjjjcthxqdwjlwrfwqgwqhckry" + "swgftgygbxsd wdfjxxxjzlpyyypayxhydqkxsaxyxgskqhykf" + "dddpplcjlhqeewxksyykdbplfjtpkjltcyyhhjttpltzzcdlsh" + "qkzjqyste eywyyzy xyysttjkllpwmcyhqgxyhcrmbxpllnqt" + "jhyylfd fxzpsftljxxjbswyysksflxlpplbbblbsfxyzsylff" + "fscjds tztryysyffsyzszbjtbctsbsdhrtjjbytcxyje xbne" + "bjdsysykgsjzbxbytfzwgenhhhhzhhtfwgzstbgxklsty mtmb" + "yxj skzscdyjrcwxzfhmymcxlzndtdh xdjggybfbnbpthfjaa" + "xwfpxmyphdttcxzzpxrsywzdlybbjd qwqjpzypzjznjpzjlzt" + " fysbttslmptzrtdxqsjehbzyj dhljsqmlhtxtjecxslzzspk" + "tlzkqqyfs gywpcpqfhqhytqxzkrsg gsjczlptxcdyyzss qz" + "slxlzmycbcqbzyxhbsxlzdltcdjtylzjyyzpzylltxjsjxhlbr" + "ypxqzskswwwygyabbztqktgpyspxbjcmllxztbklgqkq lsktf" + "xrdkbfpftbbrfeeqgypzsstlbtpszzsjdhlqlzpmsmmsxlqqnk" + "nbrddnxxdhddjyyyfqgzlxsmjqgxytqlgpbqxcyzy drj gtdj" + "yhqshtmjsbwplwhlzffny gxqhpltbqpfbcwqdbygpnztbfzj" + "gsdctjshxeawzzylltyybwjkxxghlfk djtmsz sqynzggswqs" + "phtlsskmcl yszqqxncjdqgzdlfnykljcjllzlmzjn scht" + "hxzlzjbbhqzwwycrdhlyqqjbeyfsjxwhsr wjhwpslmssgztt" + "ygyqqwr lalhmjtqjcmxqbjjzjxtyzkxbyqxbjxshzssfjlxmx" + " fghkzszggylcls rjyhslllmzxelgl xdjtbgyzbpktzhkzj" + "yqsbctwwqjpqwxhgzgdyfljbyfdjf hsfmbyzhqgfwqsyfyjgp" + "hzbyyzffwodjrlmftwlbzgycqxcdj ygzyyyyhy xdwegazyhx" + "jlzythlrmgrxxzcl ljjtjtbwjybjjbxjjtjteekhwslj lp" + "sfyzpqqbdlqjjtyyqlyzkdksqj yyqzldqtgjj js cmraqth" + "tejmfctyhypkmhycwj cfhyyxwshctxrljhjshccyyyjltktty" + "tmxgtcjtzaxyoczlylbszyw jytsjyhbyshfjlygjxxtmzyylt" + "xxypzlxyjzyzyybnhmymdyylblhlsyygqllscxlxhdwkqgyshq" + "ywljyyhzmsljljxcjjyy cbcpzjmylcqlnjqjlxyjmlzjqlycm" + "hcfmmfpqqmfxlmcfqmm znfhjgtthkhchydxtmqzymyytyyyzz" + "dcymzydlfmycqzwzz mabtbcmzzgdfycgcytt fwfdtzqssstx" + "jhxytsxlywwkxexwznnqzjzjjccchyyxbzxzcyjtllcqxynjyc" + "yycynzzqyyyewy czdcjyhympwpymlgkdldqqbchjxy " + " " + " sypszsjczc cqytsjljjt "; /** * 獲取GBK字的拼音的首字母 * 由於數據較大,完整的GBK編碼表按GBK規范分成3部分 * GBK/2為與GB2312兼容的國標漢字部分,GBK/3和GBK/4為擴展漢字部分 * 每一部分都有自己的地址計算公式 * 若輸入是acsii則返回同樣的acsii * 若輸入是中文字符則返回拼音的首字母 * 若輸入是中文字符但是該字符不知道如何發音,則返回空字符 * @param hzString * @return String * @throws UnsupportedEncodingException */URL:http://www.bianceng.cn/Programming/Java/201608/50391.htm public static String getGBKpy(String hzString) throws UnsupportedEncodingException { /* * 效率:處理大字符串(字符串有132055個byte,即70577個char)1000次,消耗時間44.474S. */ if (hzString == null || hzString.length() == 0) return ""; int pyi, len, no; int ch1code = 0, ch2code = 0; char ch1, ch2; StringBuffer pyBuffer = new StringBuffer(); byte eB[] = hzString.getBytes("GBK"); len = eB.length; //開始計算 pyi = 0; while (pyi < len) { ch1 = (char) eB[pyi]; pyi = pyi + 1; ch1code = ch1; if (ch1code > 0 && ch1code < 129) { //普通的acsii pyBuffer.append(ch1); continue; } else { //GBK字符 ch1 = (char) (256 + (int) ch1); if (eB[pyi] < 0) { ch2 = (char) (256 + (int) eB[pyi]); } else { ch2 = (char) eB[pyi]; } pyi = pyi + 1; if (pyi > len) break; } ch1code = ch1; ch2code = ch2; if (ch1code <= 254 && ch1code >= 170) { //優先處理GB-2312漢字. if (ch2code > 160) { //查找GB-2312 no = (ch1code - 176) * 94 + (ch2code - 160); pyBuffer.append(GB_2312.charAt(no - 1)); } else { //查找GBK_4 no = (ch1code - 170) * 97 + (ch2code - 63); pyBuffer.append(GBK_4.charAt(no - 1)); } }else if (ch1code <= 160 && ch1code >= 129) { //查找GBK_3 no = (ch1code - 129) * 191 + (ch2code - 63); pyBuffer.append(GBK_3.charAt(no - 1)); } else { //不是GBK漢字 continue; } } return pyBuffer.toString().trim().toLowerCase(); } public static void main(String[] args) throws Exception{ System.out.println(GetPy.getGBKpy("光谷金融港镕軍國琪")); } }
輸出ggjrgrjgq