Scanning for a substring in Icon |
|
If you want to know whether a particular target string t occurs anywhere within a string s, use the function
find ( t, s )
find()'' function fails.
find ( t, s )''
generates all the locations where t is
found (see
`Using generators in Icon').
For example, the expression
find ( "honest", "politician" )
fails, while the expression
every write ( find ( "y", "syzygy" ) ) );
writes three lines containing the numbers 2, 4, and 6 (the positions
of ``y'' characters within the string "syzygy").