| 參數(shù) | 描述 |
|---|---|
| start | 可選的。規(guī)定每次搜索的起始位置。默認(rèn)是搜索起始位置是第一個(gè)字符。如果已規(guī)定 compare 參數(shù),則必須有此參數(shù)。 |
| string1 | 必需的。需要被搜索的字符串。 |
| string2 | 必需的。需搜索的字符串。 |
| compare |
必需的。規(guī)定要使用的字符串比較類型。默認(rèn)是 0 ??刹捎孟铝兄担?/p>
|
如果 string1 為 ""(零長(zhǎng)度) - InStr 返回 0
如果 string1 為 Null - InStr 返回 Null
如果 string2 為 "" - InStr 返回 start
如果 string2 為 Null - InStr 返回 Null
如果 string2 沒有找到 - InStr 返回 0
如果在 string1 中找到 string2,InStr 返回找到匹配字符串的位置。
如果 start > Len(string1) - InStr 返回 0
dim txt,str1 txt="我是腳本之家字符串" str1=InStr(txt,"腳") response.Write(str1)
輸出結(jié)果:3
dim txt,pos txt="This is a beautiful day!" pos=InStr(txt,"his") document.write(pos)
輸出結(jié)果:2
asp從1開始計(jì)算位置
dim txt,str1 txt="我是腳本之家字符串" str1=InStr(txt,"真") response.Write(str1)
輸出結(jié)果:0
dim txt,str1 txt="我是腳本之家字符串,從第三個(gè)字符開始搜索本" str1=InStr(3,txt,"本",0) response.Write(str1)
輸出結(jié)果:4
InStr()函數(shù)在實(shí)際項(xiàng)目中的應(yīng)用案例
if InStr(wangzhi,".")= 0 Then goBack "網(wǎng)址不合法,請(qǐng)重新輸入"
下面是我寫的簡(jiǎn)單例子:
%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
% Response.CodePage=65001%>
% Response.Charset="UTF-8" %>
%
dim content_text,searchword_text
'content是內(nèi)容,searchword是要搜索的文字
sub search(content,searchword)
if InStr(content,searchword) > 0 then
Response.Write("找到")
Else
Response.Write("沒有找到")
End if
end sub
content_text = "腳本之家收集的代碼和教程是方便自己的同時(shí)方便大家,本網(wǎng)站系統(tǒng)采用自己寫的系統(tǒng),系統(tǒng)已經(jīng)寫了半年時(shí)間,主要時(shí)間放在程序的優(yōu)化上,程序一直都在更新,歡迎大家加入Q群一起討論學(xué)習(xí)。"
searchword_text = "腳本之家"
call search(content_text,searchword_text)
%>
到此這篇關(guān)于asp 用InStr查找特定字符串的代碼的文章就介紹到這了,更多相關(guān)asp InStr內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
標(biāo)簽:那曲 延邊 銅川 電商邀評(píng) 河池 優(yōu)質(zhì)小號(hào) 新鄉(xiāng) 蘇州
巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp 用InStr查找特定字符串的代碼》,本文關(guān)鍵詞 asp,用,InStr,查找,特定,字符串,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。