VBScript InStrRev 関数

定義と用法

InStrRev 関数は、ある文字列が別の文字列内に初めて現れる位置を返します。検索は文字列の終端から始まり、返される位置は文字列の先頭から数えます。

InStrRev 関数は以下の値を返します:

  • string1 が ""(長さ0)の場合、InStr は 0 を返します
  • string1 が Null の場合、InStr は Null を返します
  • string2 が "" の場合、InStr は start を返します
  • string2 が Null の場合、InStr は Null を返します
  • string2 が見つからなかった場合、InStr は 0 を返します
  • string1 内に string2 が見つかった場合、InStr は一致する文字列の位置を返します。
  • start > Len(string1) - InStr の場合、InStr は 0 を返します

ヒント:参照してください InStr 関数

構文

InStrRev(string1,string2[,start[,compare]])
パラメータ 説明
start オプション。検索の開始位置を指定します。デフォルトは最初の文字です。compare パラメータが指定されている場合、このパラメータも指定する必要があります。
string1 必須。検索する文字列です。
string2 必須。検索する文字列です。
compare

必須。使用する文字列比較の種類を指定します。デフォルトは 0 です。以下の値が使用できます:

  • 0 = vbBinaryCompare - 二進比較を実行します。
  • 1 = vbTextCompare - テキスト比較を実行します。

インスタンス

例 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!"
テキスト比較
pos=InStrRev(txt,"B",-1,1)
document.write(pos)

出力:

11

例 3

dim txt,pos
txt="This is a beautiful day!"
バイナリ比較
pos=InStrRev(txt,"T")
document.write(pos)

出力:

1

例 4

dim txt,pos
txt="This is a beautiful day!"
バイナリ比較
pos=InStrRev(txt,"t")
document.write(pos)

出力:

15