Finding

There are three built-in functions you can use for finding substrings.


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

You can use the INSTR function to return the position of a substring within a larger string.
This function is case sensitive.
When start is left blank, 1 is used.
When the substring cannot be found, 0 is returned.

InStr("C:\Temp\","C:\") = 1 
InStr(1,"C:\Temp\","C:\") = 1
InStr(1,"C:\Temp\","E:\") = 0
InStr(1,"C:\Temp\","Temp") = 4
InStr(1,"C:\Temp\","\") = 3

INSTRREV(stringcheck, stringmatch [,start] [,compare])

You can use the INSTRREV function to return the position of a substring within a larger string.
This function is case sensitive
When start is left blank, -1 is used (meaning the last character).
When the substring cannot be found, 0 is returned.
Although this function searches from the right hand side, it returns the number of characters from the left (same as INSTR).

InStrRev("C:\Temp\","C:\") = 1 
InStrRev("C:\Temp\","C:\",-1) = 1
InStrRev("C:\Temp\","E:\",-1) = 0
InStrRev("C:\Temp\","Temp",-1) = 4
InStrRev("C:\Temp\","\",-1) = 8

MID(string, start [,length])

You can use the MID function to return the text which is a substring of a larger string.
The first character position is 1.

Mid("C:\Temp\",1) = "C:\Temp\" 
Mid("C:\Temp\",3) = "\Temp\"
Mid("C:\Temp\",3,1) = "\"

Finding the first occurrence



Finding the last occurrence





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