Reputation: 49
I'm trying to check if a string exists in another string using lisp. I tried the following:
(string<= "walk" "wall")
and it gives: "3"
What i need to do is to check if the whole string in the left hand side (^walk) is in the right hand side (not the substrings), so for the previous example it should give false and with :
(string<= "walk" "walk on")
it should be true or "4".
Any help please.
Thanks in advance
Upvotes: 0
Views: 1120
Reputation: 21258
Based on your comments, you're looking for a string-prefix. The Common Lisp idiom for that is (string= pattern haystack :end2 (length pattern))
.
Upvotes: 3
Reputation: 1382
In SBCL Common Lisp
(search "walk" "wall") -> NIL
(search "walk" "walk on") -> 0
Thus 0
indicates the index of the first match. If you wanted the end of the first match you could do
(let ((pat "walk"))
(+ (length pat) (search pat "walk on"))) -> 4
Upvotes: 7