$Find()

Returns an integer character position that locates the occurrence of a substring within a string.

The format for the $FIND function is:

$F[IND](expr1,expr2[,intexpr])

$FIND() provides a tool to locate substrings. The ([) operator and the two-argument $LENGTH() are other tools that provide related functionality.

Examples of $FIND()

Example:

GTM>write $find("HIFI","I")
3
GTM>

This example uses $FIND() to WRITE the position of the first occurrence of the character "I." The return of 3 gives the position after the "found" substring.

Example:

GTM>write $find("HIFI","I",3)
5
GTM>

This example uses $FIND() to WRITE the position of the next occurrence of the character "I" starting in character position three.

Example:

GTM>set t=1 for  set t=$find("BANANA","AN",t) quit:'t  write !,t
4
6
GTM>

This example uses a loop with $FIND() to locate all occurrences of "AN" in "BANANA". $FIND() returns 4 and 6 giving the positions after the two occurrences of "AN".

Example:

GTM>set str="MUMPS databases are hierarchical"
GTM>Write $find(str," ")
7
GTM>Write $find(str,"Z")
0
GTM>Write $find(str,"d",1)
8
GTM>Write $find(str,"d",10)
0

The above example searches a string for a sub string, and returns an integer value which corresponds to the next character position after locating the sub string.