asp 漢字轉拼音-多音字的處理

來源:互聯網
上載者:User

     2008年4月份的時候 ,我在asp當中遇到一個問題,就是漢字轉為拼音的問題,裡面需要處理多音字。
在sql2000資料庫當中存著漢字的對應的拼音是這樣的   
Id  Hanzi  Pinyin
1  啊       a  e
2  你       ni
3  重       chong  zhong
4   …          …

實現的效果:
我想要的效果是如果輸入的是多音字比如“你重啊”,可以列出

(1)ni chong a
(2)ni zhong a

(3)ni chong e

(4)ni zhong e
  原來我自己用二維數組,弄了半天沒有出來。後來csdn上的 gingerkang 指點,就解決了。

 

下面是解決的方法:

主要是在sql裡面建立一個Function:

create table table_py (id int identity(1,1),hanzi nvarchar(1),pinyin nvarchar(30)) go insert into table_py (hanzi,pinyin) select '啊','a e' union all select '你','ni' union all select '重','chong zhong' go create function s2p(@s nvarchar(1)) returns @t table(pinyin nvarchar(10)) as begin if not exists(select 1 from table_py where hanzi=@s) begin insert into @t select @s return end declare @tstr nvarchar(30) select @tstr=pinyin from table_py where hanzi=@s while charindex(' ',@tstr)>0 begin insert into @t select left(@tstr,charindex(' ',@tstr)) select @tstr=stuff(@tstr,1,charindex(' ',@tstr),'') end insert into @t select @tstr return end go select * from s2p('你') t0,s2p('重') t1,s2p('啊') t2 go drop function s2p drop table table_py go

以上代碼在sql2000和sql2005中測試通過

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.