VBScriptInStrRev関数_
❮完全なVBScriptリファレンス
InStrRev関数は、ある文字列が別の文字列内で最初に出現する位置を返します。検索は文字列の末尾から始まりますが、返される位置は文字列の先頭からカウントされます。
InStrRev関数は、次の値を返すことができます。
- string1が ""の場合-InStrRevは0を返します
- string1がNullの場合-InStrRevはNullを返します
- string2が ""の場合-InStrRevはstartを返します
- string2がNullの場合-InStrRevはNullを返します
- string2が見つからない場合-InStrRevは0を返します
- string2がstring1内で見つかった場合-InStrRevは、一致が見つかった位置を返します
- start> Len(string1)の場合-InStrRevは0を返します
ヒント: InStr関数も確認してください
構文
InStrRev(string1,string2[,start[,compare]])
Parameter | Description |
---|---|
string1 | Required. The string to be searched |
string2 | Required. The string expression to search for |
start | Optional. Specifies the starting position for each search. The search begins at the last character position by default (-1) |
compare | Optional. Specifies the string comparison to use.
Default is 0 Can have one of the following values:
|
例
例1
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"beautiful"))
%>
上記のコードの出力は次のようになります。
11
例2
さまざまな開始位置を使用して、文字「i」を検索します。
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"i",-1) & "<br />")
response.write(InStrRev(txt,"i",7) & "<br />")
%>
上記のコードの出力は次のようになります。
16
6
例3
テキストとバイナリの比較で文字「T」を見つける:
<%
txt="This is a beautiful day!"
response.write(InStrRev(txt,"T",-1,1) & "<br />")
response.write(InStrRev(txt,"T",-1,0) & "<br />")
%>
上記のコードの出力は次のようになります。
15
1
❮完全なVBScriptリファレンス