VBScript InStrRev関数
完全な VBScript リファレンス
InStrRev関数は、文字列が別の文字列内で最初に出現する位置を返します。検索は文字列の末尾から開始されますが、返される位置は文字列の先頭から数えた位置です。
InStrRev関数は以下の値を返すことができます:
- string1 が "" の場合 - InStrRev は 0 を返します
- string1 が Null の場合 - InStrRev は Null を返します
- string2 が "" の場合 - InStrRev は start を返します
- string2 が Null の場合 - InStrRev は Null を返します
- string2 が見つからない場合 - InStrRev は 0 を返します
- string1 内で string2 が見つかった場合 - InStrRev は一致する文字列が見つかった位置を返します
- start > Len(string1) の場合 - 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 リファレンス その他の拡張