September 2017
Beginner
402 pages
9h 52m
English
The Str class defines a pair of methods—starts-with and ends-with—that check whether the string contains a given substring at the beginning or end of it, and return a Boolean value. Consider the following example, which displays the behavior of these methods:
say 'Hello, World'.starts-with('Hello'); # Truesay 'Hello, World'.starts-with('World'); # Falsesay 'Hello, World'.ends-with('Hello'); # Falsesay 'Hello, World'.ends-with('World'); # True
Regular expressions can be used instead of starts-with and end-with; refer to Chapter 11, Regexes, for the details.
Another set of functions—index, rindex, and indices—find the substring and return its position. The index method finds the most left occurrence ...
Read now
Unlock full access