How to check if a string s1 is a substring of another string s2?
s1
s2
For example (test-substring "f t" "df tj") --> t, (test-substring "ft" "df tj") --> nil.
(test-substring "f t" "df tj") --> t
(test-substring "ft" "df tj") --> nil
The standard Emacs Lisp approach is regular expression matching:
(string-match-p (regexp-quote needle) haystack)
Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).
cl-search can do that (and also returns the index of the substring, if found):
cl-search
ELISP> (cl-search "f t" "df tj") 1 (#o1, #x1, ?\C-a) ELISP> (cl-search "ft" "df tj") nil
Sign up using Google
Sign up using Facebook
Sign up using Stack Exchange
By posting your answer, you agree to the privacy policy and terms of service.
asked
today
viewed
87 times
active