Searches for an exact match of a substring within a String expression and returns the starting position if found (1-n).
...Instr( start, string_t, string_s )
Prerequisites
None
Parameters
start
A required numeric expression. This value specifies the first character position that is tested in string_t. Unlike the IndexOf method, a 1 specifies the first character position in string_t.
string_t
A required String expression. The String expression can be a String variable, constant, function or method, or a concatenation of these String elements. This specifies the target String that is searched for the substring, string_s.
string_s
A required String expression. The String expression can be a String variable, constant, function or method, or a concatenation of these String elements. This specifies the substring value that must be found within the string_t value.
Remarks
This method searches the value of the string_t expression for an exact, case sensitive match to the specified string_s value. The search begins at the character specified by start and continues with successive characters until either the first match is found or the end of the string_t is encountered.
Depending upon the outcome of the search, the values in Table 19-102 are returned by this method.
String Values | Returned Value |
---|---|
string_s is found in string_t |
Character position where the match begins. 1 indicates matched started at the first character of string. |
string_t has a zero length |
0 |
string_s has a zero length |
start value |
string_s not found in string_t |
0 |
Examples
Dim stg_a As String ' Create string variable
Dim pos As Integer
stg_a = "aBcDeFgHiJkLmNoPqRsTuVwXyZaBcDeFgHiJk"
pos = Instr(1, stg_a, "Fg") ' pos will be set to 6
pos = Instr(1, stg_a, "FG") ' pos will be set to 0
pos = Instr(10, stg_a, "Fg") ' pos will be set to 32
See Also