method substr-eq
Documentation for method substr-eq
assembled from the following types:
class Str
From Str
(Str) method substr-eq
multi method substr-eq(Str: Str(Cool) , Int(Cool) --> Bool)multi method substr-eq(Cool: Str(Cool) , Int(Cool) --> Bool)
Returns True
if the $test-string
exactly matches the String
object, starting from the given initial index $from
. For example, beginning with the string "foobar"
, the substring "bar"
will match from index 3:
my = "foobar";say .substr-eq("bar", 3); # OUTPUT: «True»
However, the substring "barz"
starting from index 3 won't match even though the first three letters of the substring do match:
my = "foobar";say .substr-eq("barz", 3); # OUTPUT: «False»
Naturally, to match the entire string, one merely matches from index 0:
my = "foobar";say .substr-eq("foobar", 0); # OUTPUT: «True»
Since this method is inherited from the Cool
type, it also works on integers. Thus the integer 42
will match the value 342
starting from index 1:
my = 342;say .substr-eq(42, 1); # OUTPUT: «True»
As expected, one can match the entire value by starting at index 0:
my = 342;say .substr-eq(342, 0); # OUTPUT: «True»
Also using a different value or an incorrect starting index won't match:
my = 342;say .substr-eq(42, 3); # OUTPUT: «False»say .substr-eq(7342, 0); # OUTPUT: «False»