获得汉字的拼音首字母以及整个拼音

喜欢而已 提交于 2020-01-04 01:21:19

1 SQL Server
  代码:
  获得首字母:
  CREATE function fun_getPY(@str nvarchar(4000))
returns nvarchar(4000) as
BEGIN
  declare @word nchar(1),@PY nvarchar(4000)
  set @PY=''
  while len(@str)>0
  BEGIN
    set @word=left(@str,1)
    set @PY=@PY+(case when unicode(@word) between 19968 and 19968+20901
    then (
          select top 1 PY
          from
          (
            select 'A' as PY,N'驁' as word
            union all select 'B',N'簿'
            union all select 'C',N'錯'
            union all select 'D',N'鵽'
            union all select 'E',N'樲'
            union all select 'F',N'鰒'
            union all select 'G',N'腂'
            union all select 'H',N'夻'
            union all select 'J',N'攈'
            union all select 'K',N'穒'
            union all select 'L',N'鱳'
            union all select 'M',N'旀'
            union all select 'N',N'桛'
            union all select 'O',N'漚'
            union all select 'P',N'曝'
            union all select 'Q',N'囕'
            union all select 'R',N'鶸'
            union all select 'S',N'蜶'
            union all select 'T',N'籜'
            union all select 'W',N'鶩'
            union all select 'X',N'鑂'
            union all select 'Y',N'韻'
            union all select 'Z',N'咗'
) T
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
order by PY ASC
)
else @word
end)
  set @str=right(@str,len(@str)-1)
END
return @PY
END
go

获得全部拼音
if exists (select 1 from sysobjects
   where id = object_id('pinyin')
   and type = 'U')
drop table pinyin
go

CREATE TABLE pinyin (py varchar(10) NOT NULL DEFAULT '', code int NOT NULL DEFAULT 0)    
go

INSERT INTO pinyin values('a',-20319   )
INSERT INTO pinyin values('ai', -20317 )
INSERT INTO pinyin values('an' ,-20304 )
INSERT INTO pinyin values('ang' ,-20295)
INSERT INTO pinyin values('ao' ,-20292 )
INSERT INTO pinyin values('ba' ,-20283 )
INSERT INTO pinyin values('bai', -20265)
INSERT INTO pinyin values('ban', -20257)
INSERT INTO pinyin values('bang', -20242)
INSERT INTO pinyin values('bao' ,-20230)
INSERT INTO pinyin values('bei' ,-20051)
INSERT INTO pinyin values('ben' ,-20036)
INSERT INTO pinyin values('beng' ,-20032)
INSERT INTO pinyin values('bi' ,-20026 )
INSERT INTO pinyin values('bian' ,-20002)
INSERT INTO pinyin values('biao' ,-19990)
INSERT INTO pinyin values('bie' ,-19986 )
INSERT INTO pinyin values('bin' ,-19982 )
INSERT INTO pinyin values('bing' ,-19976)
INSERT INTO pinyin values('bo' ,-19805  )
INSERT INTO pinyin values('bu' ,-19784  )
INSERT INTO pinyin values('ca' ,-19775  )
INSERT INTO pinyin values('cai' ,-19774 )
INSERT INTO pinyin values('can' ,-19763 )
INSERT INTO pinyin values('cang' ,-19756)
INSERT INTO pinyin values('cao' ,-19751 )
INSERT INTO pinyin values('ce' ,-19746  )
INSERT INTO pinyin values('ceng' ,-19741)
INSERT INTO pinyin values('cha' ,-19739 )
INSERT INTO pinyin values('chai' ,-19728)
INSERT INTO pinyin values('chan' ,-19725)
INSERT INTO pinyin values('chang' ,-19715)
INSERT INTO pinyin values('chao' ,-19540)
INSERT INTO pinyin values('che' ,-19531 )
INSERT INTO pinyin values('chen' ,-19525)
INSERT INTO pinyin values('cheng' ,-19515)
INSERT INTO pinyin values('chi' ,-19500 )
INSERT INTO pinyin values('chong' ,-19484)
INSERT INTO pinyin values('chou' ,-19479)
INSERT INTO pinyin values('chu' ,-19467 )
INSERT INTO pinyin values('chuai' ,-19289)
INSERT INTO pinyin values('chuan' ,-19288)
INSERT INTO pinyin values('chuang' ,-19281)
INSERT INTO pinyin values('chui' ,-19275 )
INSERT INTO pinyin values('chun' ,-19270 )
INSERT INTO pinyin values('chuo' ,-19263 )
INSERT INTO pinyin values('ci' ,-19261   )
INSERT INTO pinyin values('cong' ,-19249 )
INSERT INTO pinyin values('cou' ,-19243  )
INSERT INTO pinyin values('cu' ,-19242   )
INSERT INTO pinyin values('cuan' ,-19238 )
INSERT INTO pinyin values('cui', -19235  )
INSERT INTO pinyin values('cun' ,-19227  )
INSERT INTO pinyin values('cuo' ,-19224  )
INSERT INTO pinyin values('da' ,-19218   )
INSERT INTO pinyin values('dai' ,-19212  )
INSERT INTO pinyin values('dan' ,-19038  )
INSERT INTO pinyin values('dang' ,-19023 )
INSERT INTO pinyin values('dao' ,-19018  )
INSERT INTO pinyin values('de' ,-19006   )
INSERT INTO pinyin values('deng' ,-19003 )
INSERT INTO pinyin values('di' ,-18996   )
INSERT INTO pinyin values('dian' ,-18977 )
INSERT INTO pinyin values('diao' ,-18961 )
INSERT INTO pinyin values('die' ,-18952  )
INSERT INTO pinyin values('ding' ,-18783 )
INSERT INTO pinyin values('diu' ,-18774  )
INSERT INTO pinyin values('dong' ,-18773 )
INSERT INTO pinyin values('dou' ,-18763  )
INSERT INTO pinyin values('du' ,-18756   )
INSERT INTO pinyin values('duan' ,-18741 )
INSERT INTO pinyin values('dui' ,-18735  )
INSERT INTO pinyin values('dun' ,-18731  )
INSERT INTO pinyin values('duo' ,-18722  )
INSERT INTO pinyin values('e' ,-18710    )
INSERT INTO pinyin values('en' ,-18697   )
INSERT INTO pinyin values('er' ,-18696   )
INSERT INTO pinyin values('fa' ,-18526   )
INSERT INTO pinyin values('fan' ,-18518  )
INSERT INTO pinyin values('fang', -18501 )
INSERT INTO pinyin values('fei' ,-18490  )
INSERT INTO pinyin values('fen' ,-18478  )
INSERT INTO pinyin values('feng' ,-18463 )
INSERT INTO pinyin values('fo' ,-18448   )
INSERT INTO pinyin values('fou' ,-18447  )
INSERT INTO pinyin values('fu' ,-18446   )
INSERT INTO pinyin values('ga' ,-18239   )
INSERT INTO pinyin values('gai' ,-18237  )
INSERT INTO pinyin values('gan' ,-18231  )
INSERT INTO pinyin values('gang', -18220 )
INSERT INTO pinyin values('gao' ,-18211  )
INSERT INTO pinyin values('ge' ,-18201   )
INSERT INTO pinyin values('gei' ,-18184  )
INSERT INTO pinyin values('gen' ,-18183  )
INSERT INTO pinyin values('geng', -18181 )
INSERT INTO pinyin values('gong', -18012 )
INSERT INTO pinyin values('gou' ,-17997  )
INSERT INTO pinyin values('gu' ,-17988   )
INSERT INTO pinyin values('gua' ,-17970  )
INSERT INTO pinyin values('guai', -17964 )
INSERT INTO pinyin values('guan', -17961 )
INSERT INTO pinyin values('guang', -17950)
INSERT INTO pinyin values('gui' ,-17947  )
INSERT INTO pinyin values('gun' ,-17931  )
INSERT INTO pinyin values('guo' ,-17928  )
INSERT INTO pinyin values('ha' ,-17922   )
INSERT INTO pinyin values('hai' ,-17759  )
INSERT INTO pinyin values('han' ,-17752  )
INSERT INTO pinyin values('hang' ,-17733 )
INSERT INTO pinyin values('hao' ,-17730  )
INSERT INTO pinyin values('he' ,-17721   )
INSERT INTO pinyin values('hei', -17703  )
INSERT INTO pinyin values('hen', -17701  )
INSERT INTO pinyin values('heng', -17697 )
INSERT INTO pinyin values('hong', -17692 )
INSERT INTO pinyin values('hou' ,-17683  )
INSERT INTO pinyin values('hu' ,-17676   )
INSERT INTO pinyin values('hua', -17496  )
INSERT INTO pinyin values('huai', -17487 )
INSERT INTO pinyin values('huan', -17482 )
INSERT INTO pinyin values('huang', -17468)
INSERT INTO pinyin values('hui' ,-17454  )
INSERT INTO pinyin values('hun' ,-17433  )
INSERT INTO pinyin values('huo' ,-17427  )
INSERT INTO pinyin values('ji' ,-17417   )
INSERT INTO pinyin values('jia', -17202  )
INSERT INTO pinyin values('jian', -17185 )
INSERT INTO pinyin values('jiang', -16983)
INSERT INTO pinyin values('jiao' ,-16970 )
INSERT INTO pinyin values('jie' ,-16942  )
INSERT INTO pinyin values('jin' ,-16915  )
INSERT INTO pinyin values('jing', -16733 )
INSERT INTO pinyin values('jiong', -16708)
INSERT INTO pinyin values('jiu' ,-16706  )
INSERT INTO pinyin values('ju' ,-16689   )
INSERT INTO pinyin values('juan', -16664 )
INSERT INTO pinyin values('jue' ,-16657  )
INSERT INTO pinyin values('jun' ,-16647  )
INSERT INTO pinyin values('ka' ,-16474   )
INSERT INTO pinyin values('kai', -16470  )
INSERT INTO pinyin values('kan', -16465  )
INSERT INTO pinyin values('kang', -16459 )
INSERT INTO pinyin values('kao' ,-16452  )
INSERT INTO pinyin values('ke' ,-16448   )
INSERT INTO pinyin values('ken', -16433  )
INSERT INTO pinyin values('keng', -16429 )
INSERT INTO pinyin values('kong', -16427 )
INSERT INTO pinyin values('kou' ,-16423  )
INSERT INTO pinyin values('ku' ,-16419   )
INSERT INTO pinyin values('kua', -16412  )
INSERT INTO pinyin values('kuai', -16407 )
INSERT INTO pinyin values('kuan', -16403 )
INSERT INTO pinyin values('kuang', -16401)
INSERT INTO pinyin values('kui' ,-16393  )
INSERT INTO pinyin values('kun' ,-16220  )
INSERT INTO pinyin values('kuo' ,-16216  )
INSERT INTO pinyin values('la' ,-16212   )
INSERT INTO pinyin values('lai' ,-16205  )
INSERT INTO pinyin values('lan' ,-16202  )
INSERT INTO pinyin values('lang' ,-16187 )
INSERT INTO pinyin values('lao' ,-16180  )
INSERT INTO pinyin values('le' ,-16171   )
INSERT INTO pinyin values('lei', -16169  )
INSERT INTO pinyin values('leng', -16158 )
INSERT INTO pinyin values('li' ,-16155   )
INSERT INTO pinyin values('lia', -15959  )
INSERT INTO pinyin values('lian', -15958 )
INSERT INTO pinyin values('liang', -15944)
INSERT INTO pinyin values('liao' ,-15933 )
INSERT INTO pinyin values('lie' ,-15920  )
INSERT INTO pinyin values('lin' ,-15915  )
INSERT INTO pinyin values('ling', -15903 )
INSERT INTO pinyin values('liu' ,-15889  )
INSERT INTO pinyin values('long', -15878 )
INSERT INTO pinyin values('lou' ,-15707  )
INSERT INTO pinyin values('lu' ,-15701   )
INSERT INTO pinyin values('luan', -15667 )
INSERT INTO pinyin values('lue' ,-15661  )
INSERT INTO pinyin values('lun' ,-15659  )
INSERT INTO pinyin values('luo' ,-15652  )
INSERT INTO pinyin values('ma' ,-15640   )
INSERT INTO pinyin values('mai', -15631  )
INSERT INTO pinyin values('man', -15625  )
INSERT INTO pinyin values('mang', -15454 )
INSERT INTO pinyin values('mao' ,-15448  )
INSERT INTO pinyin values('me' ,-15436   )
INSERT INTO pinyin values('mei' ,-15435  )
INSERT INTO pinyin values('men' ,-15419  )
INSERT INTO pinyin values('meng', -15416 )
INSERT INTO pinyin values('mi' ,-15408   )
INSERT INTO pinyin values('mian', -15394 )
INSERT INTO pinyin values('miao', -15385 )
INSERT INTO pinyin values('mie' ,-15377  )
INSERT INTO pinyin values('min' ,-15375  )
INSERT INTO pinyin values('ming', -15369 )
INSERT INTO pinyin values('miu' ,-15363  )
INSERT INTO pinyin values('mo' ,-15362   )
INSERT INTO pinyin values('mou' ,-15183  )
INSERT INTO pinyin values('na' ,-15165   )
INSERT INTO pinyin values('nai', -15158  )
INSERT INTO pinyin values('nan', -15153  )
INSERT INTO pinyin values('nang', -15150 )
INSERT INTO pinyin values('nao' ,-15149  )
INSERT INTO pinyin values('ne' ,-15144   )
INSERT INTO pinyin values('nei', -15143  )
INSERT INTO pinyin values('nen' ,-15141  )
INSERT INTO pinyin values('neng', -15140 )
INSERT INTO pinyin values('ni' ,-15139   )
INSERT INTO pinyin values('nian', -15128 )
INSERT INTO pinyin values('niao' ,-15119 )
INSERT INTO pinyin values('nie' ,-15117  )
INSERT INTO pinyin values('nin' ,-15110  )
INSERT INTO pinyin values('ning' ,-15109 )
INSERT INTO pinyin values('niu' ,-14941  )
INSERT INTO pinyin values('nong', -14937 )
INSERT INTO pinyin values('nu' ,-14933   )
INSERT INTO pinyin values('nv' ,-14930   )
INSERT INTO pinyin values('nuan', -14929 )
INSERT INTO pinyin values('nue' ,-14928  )
INSERT INTO pinyin values('nuo' ,-14926  )
INSERT INTO pinyin values('o' ,-14922    )
INSERT INTO pinyin values('ou', -14921   )
INSERT INTO pinyin values('pa', -14914   )
INSERT INTO pinyin values('pan', -14902  )
INSERT INTO pinyin values('pang', -14894 )
INSERT INTO pinyin values('pao' ,-14889  )
INSERT INTO pinyin values('pei' ,-14882  )
INSERT INTO pinyin values('pen' ,-14873  )
INSERT INTO pinyin values('peng', -14871 )
INSERT INTO pinyin values('pi' ,-14857   )
INSERT INTO pinyin values('pian', -14678 )
INSERT INTO pinyin values('piao', -14674 )
INSERT INTO pinyin values('pie' ,-14670  )
INSERT INTO pinyin values('pin' ,-14668  )
INSERT INTO pinyin values('ping', -14663 )
INSERT INTO pinyin values('po' ,-14654   )
INSERT INTO pinyin values('pu' ,-14645   )
INSERT INTO pinyin values('qi' ,-14630   )
INSERT INTO pinyin values('qia' ,-14594  )
INSERT INTO pinyin values('qian', -14429 )
INSERT INTO pinyin values('qiang', -14407)
INSERT INTO pinyin values('qiao' ,-14399 )
INSERT INTO pinyin values('qie' ,-14384  )
INSERT INTO pinyin values('qin' ,-14379  )
INSERT INTO pinyin values('qing', -14368 )
INSERT INTO pinyin values('qiong', -14355)
INSERT INTO pinyin values('qiu' ,-14353  )
INSERT INTO pinyin values('qu' ,-14345   )
INSERT INTO pinyin values('quan', -14170 )
INSERT INTO pinyin values('que' ,-14159  )
INSERT INTO pinyin values('qun' ,-14151  )
INSERT INTO pinyin values('ran' ,-14149  )
INSERT INTO pinyin values('rang' ,-14145 )
INSERT INTO pinyin values('rao' ,-14140  )
INSERT INTO pinyin values('re' ,-14137   )
INSERT INTO pinyin values('ren', -14135  )
INSERT INTO pinyin values('reng', -14125 )
INSERT INTO pinyin values('ri' ,-14123   )
INSERT INTO pinyin values('rong', -14122 )
INSERT INTO pinyin values('rou' ,-14112  )
INSERT INTO pinyin values('ru' ,-14109   )
INSERT INTO pinyin values('ruan', -14099 )
INSERT INTO pinyin values('rui' ,-14097  )
INSERT INTO pinyin values('ruo' ,-14092  )
INSERT INTO pinyin values('sa', -14090   )
INSERT INTO pinyin values('sai', -14087  )
INSERT INTO pinyin values('san', -14083  )
INSERT INTO pinyin values('sang', -13917 )
INSERT INTO pinyin values('sao' ,-13914  )
INSERT INTO pinyin values('se' ,-13910   )
INSERT INTO pinyin values('sen', -13907  )
INSERT INTO pinyin values('seng', -13906 )
INSERT INTO pinyin values('sha' ,-13905  )
INSERT INTO pinyin values('shai', -13896 )
INSERT INTO pinyin values('shan', -13894 )
INSERT INTO pinyin values('shang', -13878)
INSERT INTO pinyin values('shao' ,-13870 )
INSERT INTO pinyin values('she' ,-13859  )
INSERT INTO pinyin values('shen' ,-13847 )
INSERT INTO pinyin values('sheng' ,-13831)
INSERT INTO pinyin values('shi' ,-13658  )
INSERT INTO pinyin values('shou', -13611 )
INSERT INTO pinyin values('shu' ,-13601  )
INSERT INTO pinyin values('shua', -13406 )
INSERT INTO pinyin values('shuai', -13404)
INSERT INTO pinyin values('shuan', -13400)
INSERT INTO pinyin values('shuang', -13398)
INSERT INTO pinyin values('shui' ,-13395 )
INSERT INTO pinyin values('shun' ,-13391 )
INSERT INTO pinyin values('shuo' ,-13387 )
INSERT INTO pinyin values('si' ,-13383   )
INSERT INTO pinyin values('song', -13367 )
INSERT INTO pinyin values('sou', -13359  )
INSERT INTO pinyin values('su' ,-13356   )
INSERT INTO pinyin values('suan', -13343 )
INSERT INTO pinyin values('sui' ,-13340  )
INSERT INTO pinyin values('sun' ,-13329  )
INSERT INTO pinyin values('suo' ,-13326  )
INSERT INTO pinyin values('ta' ,-13318   )
INSERT INTO pinyin values('tai', -13147  )
INSERT INTO pinyin values('tan', -13138  )
INSERT INTO pinyin values('tang', -13120 )
INSERT INTO pinyin values('tao' ,-13107  )
INSERT INTO pinyin values('te' ,-13096   )
INSERT INTO pinyin values('teng', -13095 )
INSERT INTO pinyin values('ti' ,-13091   )
INSERT INTO pinyin values('tian', -13076 )
INSERT INTO pinyin values('tiao', -13068 )
INSERT INTO pinyin values('tie' ,-13063  )
INSERT INTO pinyin values('ting', -13060 )
INSERT INTO pinyin values('tong', -12888 )
INSERT INTO pinyin values('tou' ,-12875  )
INSERT INTO pinyin values('tu' ,-12871   )
INSERT INTO pinyin values('tuan', -12860 )
INSERT INTO pinyin values('tui', -12858  )
INSERT INTO pinyin values('tun' ,-12852  )
INSERT INTO pinyin values('tuo' ,-12849  )
INSERT INTO pinyin values('wa' ,-12838   )
INSERT INTO pinyin values('wai' ,-12831  )
INSERT INTO pinyin values('wan' ,-12829  )
INSERT INTO pinyin values('wang', -12812 )
INSERT INTO pinyin values('wei' ,-12802  )
INSERT INTO pinyin values('wen' ,-12607  )
INSERT INTO pinyin values('weng' ,-12597 )
INSERT INTO pinyin values('wo' ,-12594   )
INSERT INTO pinyin values('wu' ,-12585   )
INSERT INTO pinyin values('xi' ,-12556   )
INSERT INTO pinyin values('xia', -12359  )
INSERT INTO pinyin values('xian', -12346 )
INSERT INTO pinyin values('xiang', -12320)
INSERT INTO pinyin values('xiao' ,-12300 )
INSERT INTO pinyin values('xie' ,-12120  )
INSERT INTO pinyin values('xin' ,-12099  )
INSERT INTO pinyin values('xing', -12089 )
INSERT INTO pinyin values('xiong', -12074)
INSERT INTO pinyin values('xiu' ,-12067  )
INSERT INTO pinyin values('xu' ,-12058   )
INSERT INTO pinyin values('xuan', -12039 )
INSERT INTO pinyin values('xue' ,-11867  )
INSERT INTO pinyin values('xun' ,-11861  )
INSERT INTO pinyin values('ya' ,-11847   )
INSERT INTO pinyin values('yan', -11831  )
INSERT INTO pinyin values('yang', -11798 )
INSERT INTO pinyin values('yao' ,-11781  )
INSERT INTO pinyin values('ye' ,-11604   )
INSERT INTO pinyin values('yi' ,-11589   )
INSERT INTO pinyin values('yin', -11536  )
INSERT INTO pinyin values('ying', -11358 )
INSERT INTO pinyin values('yo' ,-11340   )
INSERT INTO pinyin values('yong', -11339 )
INSERT INTO pinyin values('you' ,-11324  )
INSERT INTO pinyin values('yu' ,-11303   )
INSERT INTO pinyin values('yuan', -11097 )
INSERT INTO pinyin values('yue' ,-11077  )
INSERT INTO pinyin values('yun' ,-11067  )
INSERT INTO pinyin values('za' ,-11055   )
INSERT INTO pinyin values('zai' ,-11052  )
INSERT INTO pinyin values('zan' ,-11045  )
INSERT INTO pinyin values('zang', -11041 )
INSERT INTO pinyin values('zao' ,-11038  )
INSERT INTO pinyin values('ze' ,-11024   )
INSERT INTO pinyin values('zei', -11020  )
INSERT INTO pinyin values('zen' ,-11019  )
INSERT INTO pinyin values('zeng', -11018 )
INSERT INTO pinyin values('zha' ,-11014  )
INSERT INTO pinyin values('zhai', -10838 )
INSERT INTO pinyin values('zhan', -10832 )
INSERT INTO pinyin values('zhang', -10815)
INSERT INTO pinyin values('zhao' ,-10800 )
INSERT INTO pinyin values('zhe' ,-10790  )
INSERT INTO pinyin values('zhen' ,-10780 )
INSERT INTO pinyin values('zheng', -10764)
INSERT INTO pinyin values('zhi' ,-10587  )
INSERT INTO pinyin values('zhong', -10544)
INSERT INTO pinyin values('zhou', -10533 )
INSERT INTO pinyin values('zhu' ,-10519  )
INSERT INTO pinyin values('zhua', -10331 )
INSERT INTO pinyin values('zhuai', -10329)
INSERT INTO pinyin values('zhuan', -10328)
INSERT INTO pinyin values('zhuang', -10322)
INSERT INTO pinyin values('zhui' ,-10315 )
INSERT INTO pinyin values('zhun', -10309 )
INSERT INTO pinyin values('zhuo', -10307 )
INSERT INTO pinyin values('zi' ,-10296   )
INSERT INTO pinyin values('zong', -10281 )
INSERT INTO pinyin values('zou' ,-10274  )
INSERT INTO pinyin values('zu' ,-10270   )
INSERT INTO pinyin values('zuan', -10262 )
INSERT INTO pinyin values('zui' ,-10260  )
INSERT INTO pinyin values('zun' ,-10256  )
INSERT INTO pinyin values('zuo' ,-10254  )
go


if exists (select 1
           from sysobjects
           where id = object_id('fun_getPY_Whole'))
   drop Function fun_getPY_Whole
go

create function fun_getPY_Whole(@str varchar(4000))
returns varchar(4000) as
BEGIN
  declare @word varchar(10),@PY varchar(4000)
  DECLARE @v int
  declare @temp varchar(10)
  set @PY=''
  while len(@str)>0
  BEGIN
    set @word=left(@str,1)
      
    if  unicode(@word) between 19968 and 19968+20901
     begin
   
        select @v  = convert(int,substring(convert(varbinary,@word),1,1)) * 256 + convert(int,substring(convert

(varbinary,@word),2,1))-65535
 
        select @temp = MAX(py) FROM pinyin WHERE [code]<@v
   
        set @PY=@PY+@temp
     end    
    else
       set @PY=@PY +  @word

    set @str=right(@str,len(@str)-1)

END
return @PY
END
go

  参考:
http://topic.csdn.net/t/20020705/10/851769.html#
http://www.shouker.com/user4/dna/2008/4/22/121031.html
http://www.sudu.cn/info/html/edu/database/20071226/22305.html

2 c#
       //获得整个拼音
        public string GetSpell(string x)
        {
            int[] iA = new int[]
              {
                   -20319 ,-20317 ,-20304 ,-20295 ,-20292 ,-20283 ,-20265 ,-20257 ,-20242 ,-20230
                   ,-20051 ,-20036 ,-20032 ,-20026 ,-20002 ,-19990 ,-19986 ,-19982 ,-19976 ,-19805
                   ,-19784 ,-19775 ,-19774 ,-19763 ,-19756 ,-19751 ,-19746 ,-19741 ,-19739 ,-19728
                   ,-19725 ,-19715 ,-19540 ,-19531 ,-19525 ,-19515 ,-19500 ,-19484 ,-19479 ,-19467
                   ,-19289 ,-19288 ,-19281 ,-19275 ,-19270 ,-19263 ,-19261 ,-19249 ,-19243 ,-19242
                   ,-19238 ,-19235 ,-19227 ,-19224 ,-19218 ,-19212 ,-19038 ,-19023 ,-19018 ,-19006
                   ,-19003 ,-18996 ,-18977 ,-18961 ,-18952 ,-18783 ,-18774 ,-18773 ,-18763 ,-18756
                   ,-18741 ,-18735 ,-18731 ,-18722 ,-18710 ,-18697 ,-18696 ,-18526 ,-18518 ,-18501
                   ,-18490 ,-18478 ,-18463 ,-18448 ,-18447 ,-18446 ,-18239 ,-18237 ,-18231 ,-18220
                   ,-18211 ,-18201 ,-18184 ,-18183 ,-18181 ,-18012 ,-17997 ,-17988 ,-17970 ,-17964
                   ,-17961 ,-17950 ,-17947 ,-17931 ,-17928 ,-17922 ,-17759 ,-17752 ,-17733 ,-17730
                   ,-17721 ,-17703 ,-17701 ,-17697 ,-17692 ,-17683 ,-17676 ,-17496 ,-17487 ,-17482
                   ,-17468 ,-17454 ,-17433 ,-17427 ,-17417 ,-17202 ,-17185 ,-16983 ,-16970 ,-16942
                   ,-16915 ,-16733 ,-16708 ,-16706 ,-16689 ,-16664 ,-16657 ,-16647 ,-16474 ,-16470
                   ,-16465 ,-16459 ,-16452 ,-16448 ,-16433 ,-16429 ,-16427 ,-16423 ,-16419 ,-16412
                   ,-16407 ,-16403 ,-16401 ,-16393 ,-16220 ,-16216 ,-16212 ,-16205 ,-16202 ,-16187
                   ,-16180 ,-16171 ,-16169 ,-16158 ,-16155 ,-15959 ,-15958 ,-15944 ,-15933 ,-15920
                   ,-15915 ,-15903 ,-15889 ,-15878 ,-15707 ,-15701 ,-15681 ,-15667 ,-15661 ,-15659
                   ,-15652 ,-15640 ,-15631 ,-15625 ,-15454 ,-15448 ,-15436 ,-15435 ,-15419 ,-15416
                   ,-15408 ,-15394 ,-15385 ,-15377 ,-15375 ,-15369 ,-15363 ,-15362 ,-15183 ,-15180
                   ,-15165 ,-15158 ,-15153 ,-15150 ,-15149 ,-15144 ,-15143 ,-15141 ,-15140 ,-15139
                   ,-15128 ,-15121 ,-15119 ,-15117 ,-15110 ,-15109 ,-14941 ,-14937 ,-14933 ,-14930
                   ,-14929 ,-14928 ,-14926 ,-14922 ,-14921 ,-14914 ,-14908 ,-14902 ,-14894 ,-14889
                   ,-14882 ,-14873 ,-14871 ,-14857 ,-14678 ,-14674 ,-14670 ,-14668 ,-14663 ,-14654
                   ,-14645 ,-14630 ,-14594 ,-14429 ,-14407 ,-14399 ,-14384 ,-14379 ,-14368 ,-14355
                   ,-14353 ,-14345 ,-14170 ,-14159 ,-14151 ,-14149 ,-14145 ,-14140 ,-14137 ,-14135
                   ,-14125 ,-14123 ,-14122 ,-14112 ,-14109 ,-14099 ,-14097 ,-14094 ,-14092 ,-14090
                   ,-14087 ,-14083 ,-13917 ,-13914 ,-13910 ,-13907 ,-13906 ,-13905 ,-13896 ,-13894
                   ,-13878 ,-13870 ,-13859 ,-13847 ,-13831 ,-13658 ,-13611 ,-13601 ,-13406 ,-13404
                   ,-13400 ,-13398 ,-13395 ,-13391 ,-13387 ,-13383 ,-13367 ,-13359 ,-13356 ,-13343
                   ,-13340 ,-13329 ,-13326 ,-13318 ,-13147 ,-13138 ,-13120 ,-13107 ,-13096 ,-13095
                   ,-13091 ,-13076 ,-13068 ,-13063 ,-13060 ,-12888 ,-12875 ,-12871 ,-12860 ,-12858
                   ,-12852 ,-12849 ,-12838 ,-12831 ,-12829 ,-12812 ,-12802 ,-12607 ,-12597 ,-12594
                   ,-12585 ,-12556 ,-12359 ,-12346 ,-12320 ,-12300 ,-12120 ,-12099 ,-12089 ,-12074
                   ,-12067 ,-12058 ,-12039 ,-11867 ,-11861 ,-11847 ,-11831 ,-11798 ,-11781 ,-11604
                   ,-11589 ,-11536 ,-11358 ,-11340 ,-11339 ,-11324 ,-11303 ,-11097 ,-11077 ,-11067
                   ,-11055 ,-11052 ,-11045 ,-11041 ,-11038 ,-11024 ,-11020 ,-11019 ,-11018 ,-11014
                   ,-10838 ,-10832 ,-10815 ,-10800 ,-10790 ,-10780 ,-10764 ,-10587 ,-10544 ,-10533
                   ,-10519 ,-10331 ,-10329 ,-10328 ,-10322 ,-10315 ,-10309 ,-10307 ,-10296 ,-10281
                   ,-10274 ,-10270 ,-10262 ,-10260 ,-10256 ,-10254
                  };
            string[] sA = new string[]
          {
           "a","ai","an","ang","ao"

           ,"ba","bai","ban","bang","bao","bei","ben","beng","bi","bian","biao","bie","bin"
           ,"bing","bo","bu"

           ,"ca","cai","can","cang","cao","ce","ceng","cha","chai","chan","chang","chao","che"
           ,"chen","cheng","chi","chong","chou","chu","chuai","chuan","chuang","chui","chun"
           ,"chuo","ci","cong","cou","cu","cuan","cui","cun","cuo"

           ,"da","dai","dan","dang","dao","de","deng","di","dian","diao","die","ding","diu"
           ,"dong","dou","du","duan","dui","dun","duo"

           ,"e","en","er"

           ,"fa","fan","fang","fei","fen","feng","fo","fou","fu"

           ,"ga","gai","gan","gang","gao","ge","gei","gen","geng","gong","gou","gu","gua","guai"
           ,"guan","guang","gui","gun","guo"

           ,"ha","hai","han","hang","hao","he","hei","hen","heng","hong","hou","hu","hua","huai"
           ,"huan","huang","hui","hun","huo"

           ,"ji","jia","jian","jiang","jiao","jie","jin","jing","jiong","jiu","ju","juan","jue"
           ,"jun"

           ,"ka","kai","kan","kang","kao","ke","ken","keng","kong","kou","ku","kua","kuai","kuan"
           ,"kuang","kui","kun","kuo"

           ,"la","lai","lan","lang","lao","le","lei","leng","li","lia","lian","liang","liao","lie"
           ,"lin","ling","liu","long","lou","lu","lv","luan","lue","lun","luo"

           ,"ma","mai","man","mang","mao","me","mei","men","meng","mi","mian","miao","mie","min"
           ,"ming","miu","mo","mou","mu"

           ,"na","nai","nan","nang","nao","ne","nei","nen","neng","ni","nian","niang","niao","nie"
           ,"nin","ning","niu","nong","nu","nv","nuan","nue","nuo"

           ,"o","ou"

           ,"pa","pai","pan","pang","pao","pei","pen","peng","pi","pian","piao","pie","pin","ping"
           ,"po","pu"

           ,"qi","qia","qian","qiang","qiao","qie","qin","qing","qiong","qiu","qu","quan","que"
           ,"qun"

           ,"ran","rang","rao","re","ren","reng","ri","rong","rou","ru","ruan","rui","run","ruo"

           ,"sa","sai","san","sang","sao","se","sen","seng","sha","shai","shan","shang","shao","she"
           ,"shen","sheng","shi","shou","shu","shua","shuai","shuan","shuang","shui","shun","shuo","si"
           ,"song","sou","su","suan","sui","sun","suo"

           ,"ta","tai","tan","tang","tao","te","teng","ti","tian","tiao","tie","ting","tong","tou","tu"
           ,"tuan","tui","tun","tuo"

           ,"wa","wai","wan","wang","wei","wen","weng","wo","wu"

           ,"xi","xia","xian","xiang","xiao","xie","xin","xing","xiong","xiu","xu","xuan","xue","xun"

           ,"ya","yan","yang","yao","ye","yi","yin","ying","yo","yong","you","yu","yuan","yue","yun"

           ,"za","zai","zan","zang","zao","ze","zei","zen","zeng","zha","zhai","zhan","zhang","zhao"
           ,"zhe","zhen","zheng","zhi","zhong","zhou","zhu","zhua","zhuai","zhuan","zhuang","zhui"
           ,"zhun","zhuo","zi","zong","zou","zu","zuan","zui","zun","zuo"
          };
            byte[] B = new byte[2];
            string s = "";
            char[] c = x.ToCharArray();
            for (int j = 0; j < c.Length; j++)
            {
                B = System.Text.Encoding.Default.GetBytes(c[j].ToString());
                if ((int)(B[0]) <= 160 && (int)(B[0]) >= 0)
                {
                    s += c[j];
                }
                else
                {
                    for (int i = (iA.Length - 1); i >= 0; i--)
                    {
                        if (iA[i] <= (int)(B[0]) * 256 + (int)(B[1]) - 65536)
                        {
                            s += sA[i];
                            break;
                        }
                    }
                }
            }

            return s;
        }

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!