Course of Raku / Advanced / More about built-in types / Strings / Exercises / The domain part

Solution: The domain part

Here is a possible solution to the task.

Code

my $email = 'user@example.com';

my $at = $email.index('@');
say $email.substr($at + 1);

🦋 You can find the source code in the file find-domain.raku.

Output

example.com

Comments

  1. index('@') returns 4 — the zero-based position of the @ sign.

  2. substr($at + 1) starts one character past the @ and, with no length given, runs to the end of the string, yielding example.com.

Course navigation

The domain part   |   Quoting constructs 🆕