Check if a string contains a substring. Additionally, get index and number of match (Raku)

Viewed 390
1 Answers
  1. To check if it contains, use .contains to get a Bool which is a cool method.
  2. To get indices (alias indexes: both are plural of index) use .indices
  3. To get number, count the indices.
"az and az and az again".contains("az");        # True
"az and az and az again".indices("az").elems;   # 3
"az and az and az again".indices("az");         # (0 7 14)

PS: Routine indices is described just after index and rindex. So read the good doc, and read it well ;-)

Related