String matching: Difference between revisions

Added K Version
(→‎{{header|Perl 6}}: Added Perl 6 solution)
(Added K Version)
Line 593:
In fact, it happens 2 times within 'tacoloco', at indexes 2, 6.
3: Does 'tacoloco' end with 'co'? Yes.</pre>
 
=={{header|K}}==
<lang k>startswith: {:[0<#p:_ss[x;y];~*p;0]}
endswith: {0=(-#y)+(#x)-*_ss[x;y]}
contains: {0<#_ss[x;y]}</lang>
 
'''Example:'''
 
<lang k> startswith["abcd";"ab"]
1
startwith["abcd";"bc"]
0
endswith["abcd";"cd"]
1
endswith["abcd";"bc"]
0
contains["abcdef";"cde"]
1
contains["abcdef";"bdef"]
0
_ss["abcdabceabc";"abc"] / location of matches
0 4 8</lang>
 
=={{header|Liberty BASIC}}==
Line 623 ⟶ 645:
st2$="string"
if right$(st1$,len(st2$))=st2$ then
print "First string ends with second string."e
nds with second string."
end if
</lang>