Course of Raku / Regexes and grammars / Regexes / Substitution and replacement / Transliteration
Quiz — Substitution
What does the following program print?
my $s = 'hello';
$s ~~ tr/l/L/;
say $s;| 0 | hello |
| 0 | heLo |
| 1 | heLLo |
| 0 | LLLLL |
tr/// replaces characters one for one, and unlike
s/// it changes every matching character
without needing :g. Both ls in
hello become L, giving heLLo.
Course navigation
← Transliteration | Censor a word →