VBScriptのInStrRev関数
InStrRev関数は、別の文字列内の文字列の最初に出現する位置を返します。 文字列の末尾が、カウント文字列の先頭からの戻り位置から検索を開始します。
InStrRev関数は次の値を返すことができます。
- 文字列1 ""である場合 - InStrRevは、0を返します。
- 文字列1がnullの場合 - ヌルInStrRevリターン
- 文字列2 ""である場合 - 起動に戻りますInStrRev
- 文字列2がNULLの場合 - ヌルInStrRevリターン
- 文字列2が見つからない場合 - InStrRevは、0を返します。
- string2のは、文字列1の中に発見された場合には - 一致する文字列の場所を見つけるに戻るInStrRev
- スタート>レン(文字列1)の場合 - InStrRevは、0を返します。
ヒント:InStr関数を参照してください。
文法
InStrRev(string1,string2[,start[,compare]])
参数 | 描述 |
---|---|
string1 | 必需。需要被搜索的字符串。 |
string2 | 必需。需要搜索的字符串表达式。 |
start | 可选。规定每次搜索的起始位置。默认的搜索起始位置是最后一个字符(-1)。 |
compare | 可选。规定要使用的字符串比较类型。默认是 0。 可采用下列的值:
|
例
例1
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"beautiful"))
</script>
上記の出力の例:
11
»をお試しください
例2
別の開始位置で、文字の "i"を見つけます:
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"i",-1) & "<br />")
document.write(InStrRev(txt,"i",7) & "<br />")
</script>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"i",-1) & "<br />")
document.write(InStrRev(txt,"i",7) & "<br />")
</script>
上記の出力の例:
16
6
6
»をお試しください
例3
テキストとバイナリ比較の両方を使用して、文字「T」を検索します。
<script type="text/vbscript">
txt="This is a beautiful day!"
document.write(InStrRev(txt,"T",-1,1) & "<br />")
document.write(InStrRev(txt,"T",-1,0) & "<br />")
</script>
txt="This is a beautiful day!"
document.write(InStrRev(txt,"T",-1,1) & "<br />")
document.write(InStrRev(txt,"T",-1,0) & "<br />")
</script>
上記の出力の例:
15
1
1
»をお試しください
完全なVBScriptのリファレンス