The $FIND function is a special function built into M to allow you to search strings for certain substrings. You call call $FIND in one of three ways:
And it accepts any sort of capitalization: $Find, $find, $f, $FInd, $FiNd, are all syntactically correct, though they may not abide by the style guidelines of your project.
The $FIND function takes two or three arguments as input:
$FIND("Hello","el") $FIND("Hello","el",2) $FIND(STRING1,STRING2) $FIND(STRING1,STRING2,INT)
It should be noted that as a special function, you cannot use $FIND as a command, for instance:
is not a valid line of M code, you can only use it in conjunction with a line command, like in the following examples:
GTM>WRITE $FIND("I am a pidgeon","p") 9 GTM>SET X=$FIND("I am a cat","a c") GTM>WRITE X 9 GTM>WRITE $FIND("I can plant a tree on the moon","e", 20) 26
The $FIND function will return one of three things: * If it finds a substring, it returns the index after the last character in the substring, index+1. * If it does not find the substring, it returns zero. Examples:
GTM>WRITE $FIND("I","I") 2 GTM>WRITE $FIND("I","A") 0
It is important to note that M, unlike C, includes whitespace in it’s syntax, so that you cannot have a space after the comma seperating your arguments:
GTM>WRITE $FIND("I", "A")
Will break on you.