String matching: Difference between revisions

→‎{{header|Perl 6}}: Only show sensible ways to do it
(→‎{{header|Perl 6}}: The "full program" boilerplate was obscuring the interesting stuff. Show individual expressions only, like the #Perl solution.)
(→‎{{header|Perl 6}}: Only show sensible ways to do it)
Line 2,068:
so $haystack ~~ / $needle / # True if $haystack contains $needle
so $haystack ~~ / $needle $/ # True if $haystack ends with $needle</lang>
 
Using <code>index</code>:
 
<lang perl6>so ($_ == 0 with $haystack.index($needle)) # True if $haystack starts with $needle
defined $haystack.index($needle) # True if $haystack contains $needle
so ($_ == $haystack.chars - $needle.chars with $haystack.rindex($needle)) # True if $haystack ends with $needle</lang>
 
Using <code>substr</code>:
Anonymous user