Course of Raku / Advanced / More about built-in types / Strings / Exercises / Acronym

Solution: Acronym

Here is a possible solution to the task.

Code

my $phrase = 'hyper text markup language';

my $acronym = '';
for $phrase.words -> $word {
    $acronym ~= $word.substr(0, 1);
}

say $acronym.uc;

🦋 You can find the source code in the file acronym.raku.

Output

HTML

Comments

  1. $phrase.words gives the list of words. The loop takes the first character of each one with substr(0, 1) and appends it to $acronym.

  2. Once all the initials are collected, uc turns the result into upper case: HTML.

Course navigation

Acronym   |   The domain part