Course of Raku / Addendum 🆕 / Working with data / Text and strings / Exercises / Count the vowels
Solution: Count the vowels
Here is a possible solution to the task.
Code
my $text = 'Programming in Raku';
say +$text.comb(/ <[aeiouAEIOU]> /);🦋 You can find the source code in the file count-vowels.raku.
Output
6Comments
Passing a regex to
.combreturns every matching character. The character class<[aeiouAEIOU]>lists the vowels in both cases.The prefix
+puts the resulting list into numeric context, giving its length — the number of vowels.
Course navigation
← Count the vowels | Title case →