InStr Function

2 つの文字列の一方が、他方の文字列中のどの位置にあるかを返します。

Instr 関数からは、文字列の一致した位置が返されます。一致する部分がない場合は、0 が返されます。

構文:


InStr ([Start As Integer,] Text1 As String, Text2 As String[, Compare])

戻り値:

整数

パラメーター:

Start: A numeric expression that marks the position in a string where the search for the specified substring starts. If you omit this parameter, the search starts at the first character of the string. The minimum allowed value is 1. The maximum allowed value is 2,147,483,648.

Text1: 検索対象とする文字列の表式。

Text2: 検索文字列の表式。

Compare:比較の種類を指定する数値表式 (省略可)。このパラメーターの値には 0 または 1 を指定できます。デフォルト値は 1 は、大文字と小文字の区別がないテキスト比較を指定します。値 0 は、大文字と小文字を区別するバイナリ比較を指定します。

最初のパラメーターを省略した場合に Compare パラメータを指定すると、実行時エラーが発生することがあります。

Error codes:

5 無効なプロシージャー呼び出しです

例:


Sub ExamplePosition
Dim sInput As String
Dim iPos As Integer
    sInput = "Star Suite"
    iPos = Instr(sInput,"v")
    Print iPos
End Sub

ご支援をお願いします!