Methods by type

String tests & search

Full

Boolean substring tests and finding positions — contains, starts-with, indices.

Beyond .index, Str has Boolean predicates for the common "does it contain / begin / end with" questions, plus .indices for every position.

Boolean substring tests #

say "hello".contains("ell");
say "hello".starts-with("he");
say "hello".ends-with("lo");
Output
True
True
True

These read better than comparing an .index against -1 (Raku returns Nil, not -1, for a missing substring anyway).

All positions — indices #

.indices returns every start position of the substring, in order.

say "hello".indices("l");
Output
(2 3)

Notes #