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:D:  Str(Cool$test-stringInt(Cool$from --> Bool)
multi method substr-eq(Cool:D: Str(Cool$test-stringInt(Cool$from --> 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 $string = "foobar";
say $string.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 $string = "foobar";
say $string.substr-eq("barz"3);   # OUTPUT: «False␤»

Naturally, to match the entire string, one merely matches from index 0:

my $string = "foobar";
say $string.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 $integer = 342;
say $integer.substr-eq(421);      # OUTPUT: «True␤»

As expected, one can match the entire value by starting at index 0:

my $integer = 342;
say $integer.substr-eq(3420);     # OUTPUT: «True␤»

Also using a different value or an incorrect starting index won't match:

my $integer = 342;
say $integer.substr-eq(423);      # OUTPUT: «False␤» 
say $integer.substr-eq(73420);    # OUTPUT: «False␤»