Fork me on GitHub
#clojurescript
<
2021-07-25
>
Richard Bowen03:07:16

Hey, how do I check if a string contains a particular character or sequence of characters in ClojureScript?

Richard Bowen03:07:05

Would I have to use clojure.string/includes?

p-himik06:07:31

That, or JS interop.

Richard Bowen23:07:24

Thanks. I went with clojure.string/includes?

Richard Bowen23:07:03

Hey, say I would like to render an element conditionally using an if, how would I express that in ClojureScript? It seems straight forward but my attempt always seems to execute what should be the else. I tried something like this:

(if (clojure.string/includes? "this" "this and that")
 [:div {} "Something"]
 [:img {:src "/images/image.png"}])

phronmophobic23:07:11

you might have the arguments swapped

phronmophobic23:07:33

> (clojure.string/includes? "this" "this and that")
false
> (clojure.string/includes? "this and that" "this" )
true