String matching: Difference between revisions

Content added Content deleted
(Using built-in functions)
(Added Quackery.)
Line 3,531: Line 3,531:
loc = "abab".find("ab") #returns 0
loc = "abab".find("ab") #returns 0
loc = "abab".find("ab",loc+1) #returns 2</lang>
loc = "abab".find("ab",loc+1) #returns 2</lang>

=={{header|Quackery}}==

<lang Quackery>
[ tuck size split drop = ] is starts ( $ $ --> b )

[ tuck size negate split nip = ] is ends ( $ $ --> b )

[ 2dup = iff true
else
[ over $ "" = iff false done
2dup starts iff true done
dip behead nip again ]
dip 2drop ] is contains ( $ $ --> b )
[ iff
[ say "true" ]
else
[ say "false" ] ] is echobool ( b --> )
$ "abcdefgh" $ "abc" starts echobool cr
$ "abcdefgh" $ "xyz" starts echobool cr
$ "abcdefgh" $ "fgh" ends echobool cr
$ "abcdefgh" $ "xyz" ends echobool cr
$ "abcdefgh" $ "cde" contains echobool cr
$ "abcdefgh" $ "xyz" contains echobool cr</lang>

{{out}}

<pre>true
false
true
false
true
false
</pre>


=={{header|Racket}}==
=={{header|Racket}}==