Purpose
Returns a character position, indicating where a substring first appears within another string. You can call this function from the MapBasic window in MapInfo Pro.
Syntax
InStr( position, string, substring )
position is a positive integer, indicating the start position of the search.
string is a string expression.
substring is a string expression which we will try to locate in string.
Return Value
Integer
Description
The InStr() function tests whether the string expression string contains the string expression substring. MapBasic searches the string expression, starting at the position indicated by the position parameter; thus, if the position parameter has a value of one, MapBasic will search from the very beginning of the string parameter.
If string does not contain substring, the InStr() function returns a value of zero.
If string does contain substring, the InStr() function returns the character position where the substring appears. For example, if the substring appears at the very start of the string, InStr() will return a value of one.
If the substring parameter is a null string, the InStr() function returns zero.
The InStr() function is case-sensitive. In other words, the InStr() function cannot locate the substring "BC" within the larger string "abcde", because "BC" is upper-case.
Error Conditions
ERR_FCN_ARG_RANGE (644) error generated if an argument is outside of the valid range
Example
Dim fullname As String, pos As Integer
fullname = "New York City"
pos = InStr(1, fullname, "York")
' pos will now contain a value of 5 (five)
pos = InStr(1, fullname, "YORK")
' pos will now contain a value of 0;
' YORK is uppercase, so InStr will not locate it
' within the string "New York City"
See Also:
Mid$() function