asp搜索輸出中間結(jié)果

字號:


    代碼如下:
    <%
    str1="關(guān)鍵詞"
    str2="文章內(nèi)容文章內(nèi)容文章內(nèi)容文章內(nèi)容文章內(nèi)容文關(guān)鍵詞章內(nèi)容文章內(nèi)容文章內(nèi)容文章內(nèi)容文章內(nèi)容文章內(nèi)容"
    tmp=instr(str2,str1) '獲取關(guān)鍵詞在文章的位置
    b=tmp-20'將該位置遷移20個(gè)字符位
    if b<=0 then'如果該位置到最前了,也就是文章的開頭.那從開頭開始
    b=1
    end if
    outstr=mid(str2,b,tmp+20+len(str1))'獲取內(nèi)容,用mid函數(shù)將關(guān)鍵詞所在位置的40個(gè)字取出
    outstr=replace(outstr,str1,"<font color=red>"&str1&"</font>")'替換為紅顏色
    response.Write outstr
    %>