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