Returns an integer character position that locates the occurrence of a substring within a string.
The format for the $FIND function is:
The first expression specifies the string within which $FIND() searches for the substring.
The second expression specifies the substring for which $FIND() searches.
The optional integer expression identifies the starting position for the $FIND() search. If this argument is missing, zero (0), or negative, $FIND() begins its search in the first position of the string.
If $FIND() locates the substring, it returns the position after the last character of the substring. If the end of the substring coincides with the end of the string (expr1), it returns an integer equal to the length of the string plus one ($L(expr1)+1).
If $FIND() does not locate the substring, it returns zero (0).
For a process started in UTF-8 mode, $FIND() interprets the string arguments as UTF-8 encoded. With VIEW "BADCHAR" enabled, $FIND() produces a run-time error when it encounters a malformed character, but it does not process the characters that fall after the span specified by the arguments.
$ZFIND() is the Z equivalent function $FIND(). Irrespective of the settings of VIEW "BADCHAR" and $ZCHSET, $ZFIND() interprets argument as a sequence of bytes (rather than a sequence of characters) and can perform byte-oriented $FIND() operations.For more information, refer to “$ZFind()”.
$FIND() provides a tool to locate substrings. The ([) operator and the two-argument $LENGTH() are other tools that provide related functionality.
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.
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.
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".
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.