INSTR([start] ,string1 ,string2 [,compare])

Returns the position of a substring within a larger string (Long).

start(Optional) The character position to start searching from (Integer).
string1The text string containing your substring (String).
string2The text string to look for (String).
compare(Optional) A vbCompareMethod constant specifying the type of string comparison to use (Integer):
-1 = vbUseCompareOption (uses the "Option Compare" setting)
0 = vbBinaryCompare (default, case sensitive)
1 = vbTextCompare
2 = vbDatabaseCompare (uses an Access database)

* This is case sensitive by default.
* If "start" is left blank, then 1 is used. (i.e. you start searching from the first character).
* If "start" is 0, then a run-time error occurs.
* If "start" is Null, then an error occurs.
* If "string1" cannot be found in "string2" then 0 is returned.
* If "string1" = "string2" or "string1" is the beginning of "string2" then 1 is returned.
* If "compare" is left blank, then -1 is used. If there is no Option Compare statement provided then vbBinaryCompare (0) is used.
* If "compare" is null, then an error occurs.
* You can use the INSTRREV function to start at the end.
* You can use the INSTR$ function to return a String data type instead of Variant/String data type.
* If you type in INSTR$ with valid arguments the editor will automatically change this function to just INSTR.
* You can use the INSTRB function that is used with byte data.
* For more information, refer to the Finding Strings page.
* The equivalent .NET function is Microsoft.VisualBasic.Strings.InStr
* For the Microsoft documentation refer to

InStr("C:\Temp\","C:\") = 1 
InStr(1,"C:\Temp\","C:\") = 1
InStr(1,"C:\Temp\","E:\") = 0
InStr(1,"somemoretext","more") = 5
InStr("somemoretext","more") = 5
InStr("somemoretext","somemoretext") = 1
InStr("somemoretext","nothing") = 0

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top