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
1 = vbTextCompare
2 = vbDatabaseCompare (uses an Access database)

REMARKS
* This is case sensitive by default.
* If "string1" cannot be found in "string2" then 0 is returned.
* If "start" is left blank, then 1 is used. (i.e. you start searching from the first character).
* If "start" is null, then an error occurs.
* 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.
* If "compare" is provided, the "start" must also be provided ?
* If "string1" = "string2" or "string1" is the beginning of "string2" then 1 is returned.
* 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.
* This function was added in Office 2000.
* The equivalent .NET function is Microsoft.VisualBasic.Strings.InStr
* For the Microsoft documentation refer to docs.microsoft.com

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

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