Methods by type
String tests & search
FullBoolean 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
TrueThese 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 #
.contains,.starts-with,.ends-withaccept a string or a regex, so.contains(/\d/)tests for any digit..indexreturns the first position (orNil);.rindexsearches from the end.- For extracting the matched pieces rather than testing, use
.combor a regex match — see String methods.