Methods by type

String methods

Full

The everyday Str toolkit — case, trimming, indexing, splitting into pieces.

Str carries a large method set. These are the ones you reach for constantly: changing case, trimming, locating and slicing substrings, and breaking a string into characters or matches.

Length, case, reversal #

say "Hello".chars;
say "Hello".uc;
say "Hello".flip;
Output
5
HELLO
olleH

Trim, index, substr #

trim removes surrounding whitespace, index finds a substring's position (zero-based), and substr extracts a slice by start and length.

say "  hi  ".trim;
say "hello".index("l");
say "hello".substr(1, 3);
Output
hi
2
ell

comb — break into pieces #

comb returns the matching pieces of a string: with no argument, each character; with a regex, each match.

say "hello".comb;
say "a1b2c3".comb(/\d/);
Output
(h e l l o)
(1 2 3)

trans — translate characters #

trans maps characters to replacements, like tr/// in other languages.

say "hello".trans("el" => "ip");
Output
hippo

Notes #