instr

Searches for a string within a string.

Available in:

Apps (win) Apps (char) Reportwriter RPC Standalone PL
X X X X X

Syntax

int instr(char1,char2[,n[,m]])
string    char1,char2
int       n,m

Description

char1 specifies the string in which to search.

char2 specifies the string to search for. The position of char2 is relative to the first character of char1, even when n > 1.

n (optional) specifies the place at which to begin searching. If the value of the parameter is negative, the search begins from the back of the string.

m (optional) specifies the occurrence.

Notes

If m and/or n are not specified, 1 is assumed. If char1 or char2 is NULL, a NULL is returned. If char2 does not exist in char1, 0 is returned.

Example

Prints the location of two strings within a given string.
{
 char s[80], t[80], u[80];
 s = "This is an example for Trifox's TRIMpl";
 t = "Trifox";
 u = "No";
 printf("The location of Trifox within the string is " ^^ instr(s,t));
 printf("The location of No within the string is " ^^ instr(s, u));
}
The following returns the position of the last slash (/), in this case, 22. Note that the position is always returned from the beginning of the string and that it is 1-based.
instr("/usr2/rad/cheetah/lib/trim.ini", "/", -1)