RosettaCodeData/Task/String-matching/Sidef/string-matching.sidef

16 lines
412 B
Plaintext
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

var first = "abc-abcdef-abcd";
var second = "abc";
say first.begins_with(second); #=> true
say first.contains(second); #=> true
say first.ends_with(second); #=> false
# Get and print the location of the match
say first.index(second); #=> 0
# Find multiple occurrences of a string
var pos = -1;
while (pos = first.index(second, pos+1) != -1) {
say "Match at pos: #{pos}";
}