asp 的 分詞實現代碼

來源:互聯網
上載者:User

<%
a="日本是中國的一個省|我們美麗中國的張家界!"
b="中國,我們,張家界,日本,美國,蘋果"
b=split(b,",")
a=split(a,"|")
for k=0 to ubound(a)
s=""
n=""
for i=0 to ubound(b)
if instr(a(k),b(i))>0 then
s=s & instr(a(k),b(i)) & "," &instr(a(k),b(i))+len(b(i)) & ","
end if
next
s=left(s,len(s)-1)
if left(s,len(s)-1)<>len(a(k)) then s=s&","&len(a(k))+1
s=sort(split(s,","))
for i=0 to ubound(s)-1
n=n&mid(a(k),s(i),s(i+1)-s(i))& "|"
next
response.write n & "<br>"
next

function sort(ary)
ck=true
do Until ck = false
ck=false
For f = 0 to UBound(ary) -1
if clng(ary(f))>clng(ary(f+1)) then
v1=clng(ary(f))
v2=clng(ary(f+1))
ary(f)=v2
ary(f+1)=v1
ck=true
end if
next
loop
sort=ary
end function
%>

運行結果

日本|是|中國|的一個省|
我們|美麗|中國|的|張家界|!|

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.