Methods by type

samecase

Full

Recase a string to follow the case pattern of another.

.samecase(pattern) rewrites a string's letters to match the upper/lower case pattern of a second string, position by position (the last case carries onward).

Matching a case pattern #

say "hello".samecase("AB");
Output
HELLO

The pattern "AB" is all uppercase, so hello becomes HELLO.

Following a mixed pattern #

The case is copied position by position, and the last case in the pattern carries on to the rest of the string — so "Ab" gives an initial capital then lowercase.

say "world".samecase("Ab");
say "WORLD".samecase("abc");
Output
World
world

"Ab" title-cases (W upper, the rest lower); "abc" is all lowercase, so WORLD becomes world.

Notes #