| Navigation: Language Reference > 13 - Built-in Functions >====== INSTRING (return substring position) ======
INSTRING(substring,string [,step] [,start])
Returns an unsigned integer value from zero to the length of the search string.
| Searches for a substring in a string.
| A string constant, variable, or expression that contains the string for which to search. You should CLIP a variable substring so INSTRING will not look for a match that contains the trailing spaces in the variable.
| A string constant, or the label of the STRING, CSTRING, or PSTRING variable to be searched.
| A numeric constant, variable, or expression which specifies the step length of the search. A step of 1 will search for the substring beginning at every character in the string, a step of 2 starts at every other character, and so on. A negative step value (-1) will search from right to left within the string. If step is omitted, the step length defaults to the length of the substring.
| A numeric constant, variable, or expression which specifies where to begin the search of the string. If omitted, the search starts at the first character position. ClarionWin32 The first character position is one (1) Clarion# The first character position is zero (0)
The INSTRING procedure steps through a string, searching for the occurrence of a substring. If the substring is found, the procedure returns the step number on which the substring was found.
If the substring is not found in the string, INSTRING returns zero.
In Clarion# indexing starts with 0, so if the substring is not found then -1 is returned.
INSTRING starts to search for substring from the start position in the string and moves from right to left if the step is a positive number, or from left to right if step is a negative number until the substring is found. If the length of the unchecked portion of the string is less than length of the search substring the search stops.
If the search substring is not found INSTRING returns zero.
If the search substring is found, the result is equal to the number of steps from the origin of the string to the found position. If the value of step is not equal to 1, the result is rounded up to the whole number of steps as follows: