VBScript InStrRev 函數(shù)
定義和用法
InStrRev 函數(shù)可返回一個(gè)字符串在另一個(gè)字符串中首次出現(xiàn)的位置。搜索從字符串的末端開(kāi)始,但是返回的位置是從字符串的起點(diǎn)開(kāi)始計(jì)數(shù)的。
InStrRev 函數(shù)可返回下面的值:
- 如果 string1 為 ""(零長(zhǎng)度) - InStr 返回 0
- 如果 string1 為 Null - InStr 返回 Null
- 如果 string2 為 "" - InStr 返回 start
- 如果 string2 為 Null - InStr 返回 Null
- 如果 string2 沒(méi)有找到 - InStr 返回 0
- 如果在 string1 中找到 string2,InStr 返回找到匹配字符串的位置。
- 如果 start > Len(string1) - InStr 返回 0
提示:請(qǐng)參閱 InStr 函數(shù)。
語(yǔ)法
InStrRev(string1,string2[,start[,compare]])
參數(shù) | 描述 |
---|---|
start | 可選的。規(guī)定每次搜索的起始位置。默認(rèn)是搜索起始位置是第一個(gè)字符。如果已規(guī)定 compare 參數(shù),則必須有此參數(shù)。 |
string1 | 必需的。需要被搜索的字符串。 |
string2 | 必需的。需搜索的字符串。 |
compare |
必需的。規(guī)定要使用的字符串比較類型。默認(rèn)是 0 ?刹捎孟铝兄担
|
實(shí)例
例子 1
dim txt,pos
txt="This is a beautiful day!"
pos=InStrRev(txt,"his")
document.write(pos)
輸出:
2
例子 2
dim txt,pos
txt="This is a beautiful day!"
'textual comparison
pos=InStrRev(txt,"B",-1,1)
document.write(pos)
輸出:
11
例子 3
dim txt,pos
txt="This is a beautiful day!"
'binary comparison
pos=InStrRev(txt,"T")
document.write(pos)
輸出:
1
例子 4
dim txt,pos
txt="This is a beautiful day!"
'binary comparison
pos=InStrRev(txt,"t")
document.write(pos)
輸出:
15