Returns an integer byte position that locates the occurrence of a byte sequence within a sequence of octets(8-bit bytes).
The format of the $ZFIND function is:
$ZF[IND](expr1,expr2[,intexpr])
The first expression specifies the sequence of octets (8-bit bytes) in which $ZFIND() searches for the byte sequence.
The second expression specifies the byte sequence for which $ZFIND() searches.
The optional integer expression identifies the starting byte position for the $ZFIND() search. If this argument is missing, zero (0), or negative, $ZFIND() begins to search from the first position of the sequence of octets (8-bite bytes).
If $ZFIND() locates the byte sequence, it returns the position after its last byte. If the end of the byte sequence coincides with the end of the sequence of octets (expr1), it returns an integer equal to the byte length of the expr1 plus one ($L(expr1)+1).
If $ZFIND() does not locate the byte sequence, it returns zero (0).
$ZFIND() provides a tool to locate byte sequences. The ( [ ) operator and the two-argument $ZLENGTH() are other tools that provide related functionality.
Example:
GTM>write $zfind("主要雨",$zchar(187))
4
GTM>
This example uses $ZFIND() to WRITE the position of the first occurrence of the numeric byte code 150. The return of 3 gives the position after the "found" byte.
Example:
GTM>write $zfind("新年好",$zchar(229),5)
8
GTM>
This example uses $ZFIND() to WRITE the position of the next occurrence of the byte code 229 starting in byte position five.
Example:
GTM>set t=1 for set t=$zfind("新年好",$zchar(230,150,176),t) quit:'t write !,t
4
GTM>
This example uses a loop with $ZFIND() to locate all the occurrences of the byte sequence $ZCHAR(230,150,176) in the sequence of octets ("新年好"). The $ZFIND() returns 4 giving the position after the occurrence of byte sequence $ZCHAR(230,150,176).