字元/單詞提取與過濾

來源:互聯網
上載者:User

http://community.csdn.net/Expert/topic/5760/5760639.xml?temp=.3635828

解此題得總結出的一段代碼。備用 

 

<!--
類比1W條記錄,速度過得去。
本法按允許集中尋找待處理單詞,如果允許集中存在那麼就取出.最終得到一串待處理字串中含有的所有允許單詞.若還有看不明白的地方,請指出來,我再加註.總不能搞得每行加註吧?!我可沒寫過教程,難度很大的.
-->
<%
Dim     rtype,strA
rtype    =lcase(trim(request("rtype")))    ''字串類別
strA    =trim(request("strA"))  ''要處理的字串.''調試代碼
rtype    ="word" ''字串以限制為word
rtype    ="number" ''字串以限制為數值
rtype    =""  ''字串以限制為字母
strA    ="abcdef 123 abcd 1234567 d abcdef 1234567 a asdf abcdef 1234 ab"
''============調試結束,以上代碼非調試時請刪除.''不同類型分別處理
select case rtype
case "word": ''字串以限制為word
    response.Write(checkWords(strA))
case "number": ''字串以限制為數值
    response.Write(checkNumbers(strA))
case else:  ''字串以限制為字母,預設類別
    response.Write(checkAz(strA))
end select''字母處理函數
Function checkAz(vNewStr)
    Dim     tmp_str,tmp_arr,tmp_strB,tmp_arr_up,tmp_i
 ''待處理字串產生數組
    tmp_str    =vNewStr
    tmp_arr    =split(tmp_str," ")
    tmp_arr_up    =ubound(tmp_arr)
   
    ''類比取出允許集
    tmp_strB=" a b c d "
   
 ''待處理字串中的單詞在允許集中存在則提取出來.
    checkAz=""
    for tmp_i=0 to tmp_arr_up
        if instr(tmp_strB," "&tmp_arr(tmp_i)&" ")>0 then
            checkAz=checkAz&" "&tmp_arr(tmp_i)
        end if
    next
 ''傳回值
    checkAz    =ltrim(checkAz)
End Function''數文書處理函數
Function checkNumbers(vNewStr)
    Dim     tmp_str,tmp_arr,tmp_strB,tmp_arr_up,tmp_i
 ''待處理字串產生數組
    tmp_str    =vNewStr
    tmp_arr    =split(tmp_str," ")
    tmp_arr_up    =ubound(tmp_arr)
   
    ''類比取出允許集
    tmp_strB=" "
    for tmp_i=1 to 10000
        tmp_strB=tmp_strB&"1234567 "
    next
   
 ''待處理字串中的單詞在允許集中存在則提取出來.
    checkNumbers=""
    for tmp_i=0 to tmp_arr_up
        if instr(tmp_strB," "&tmp_arr(tmp_i)&" ")>0 then
            checkNumbers=checkNumbers&" "&tmp_arr(tmp_i)
        end if
    next
 ''傳回值
    checkNumbers    =ltrim(checkNumbers)
End Function''單詞處理函數
Function checkWords(vNewStr)
    Dim     tmp_str,tmp_arr,tmp_strB,tmp_arr_up,tmp_i
 ''待處理字串產生數組
    tmp_str    =vNewStr
    tmp_arr    =split(tmp_str," ")
    tmp_arr_up    =ubound(tmp_arr)
   
    ''類比取出允許集
    tmp_strB=" "
    for tmp_i=1 to 10000
        tmp_strB=tmp_strB&"abcdef "
    next
   
 ''待處理字串中的單詞在允許集中存在則提取出來.
    checkWords=""
    for tmp_i=0 to tmp_arr_up
        if instr(tmp_strB," "&tmp_arr(tmp_i)&" ")>0 then
            checkWords=checkWords&" "&tmp_arr(tmp_i)
        end if
    next
 ''傳回值
    checkWords    =ltrim(checkWords)
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.