Product Site

5.1.7.54. containsWord

Returns .true if phrase is found in the receiving string. Returns .false if phrase contains no words or if phrase is not found. Multiple whitespace characters between words in either phrase or the receiving string are treated as a single blank for the comparison, but, otherwise, the words must match exactly.

By default the search starts at the first word in the receiving string. You can override this by specifying start (which must be positive whole number), the word at which the search is to be started.

See also

Example 5.92. String class — containsWord method
good = "Now is the time for all good men"
say good~containsWord("the")          -- .true
say good~containsWord("The")          -- .false
say good~containsWord("is the")       -- .true
say good~containsWord("is   the ")    -- .true
say good~containsWord("is time")      -- .false
say good~containsWord("time")         -- .true
say good~containsWord("time", 5)      -- .false