Reputation: 27
I was wondering how one would compare strings for a partial match. For example,
to see if the phrase "example" is found in a sentence, say "this is an example"?
Upvotes: 3
Views: 1949
Reputation: 18917
In Racket the general mechanism for this are regular expressions:
(regexp-match "example" "this is an example")
=> '("example")
(regexp-match-positions "example" "this is an example")
=> '((11 . 18))
Regular expressions are a slightly complex but very powerful way of processing strings. You can specify if the search string needs to be a separate word, search for repetitive patterns or character classes. See the excellent Racket doc for this.
Upvotes: 3
Reputation: 223013
Use string-contains
from SRFI 13:
> (require srfi/13)
> (string-contains "this is an example" "example")
11
> (string-contains "this is an example" "hexample")
#f
Upvotes: 3