There doesn't seem to be a built-in CLJS method to check for the index of a substring (e.g. the index of "scr" in "clojurescript" is 7). This can be done with regexes as described in this question, but that's quite verbose and is a little bit overkill for common use. Is there any way to quickly and easily check for the existence of a character or substring within a string?
Because ClojureScript has access to all native JavaScript, we can use built-in JS functions like .indexOf. This makes it fairly simple to do things like:
> (.indexOf "clojurescript" "scr")
7
As Joaquin noted, this also makes it very simple to determine the existence of a substring as well:
> (not= -1 (.indexOf "clojurescript" "scr"))
true
> (not= -1 (.indexOf "clojurescript" "asd"))
false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With