Checking whether string ends with given string in clojure
clojure, string
Solution
You can access the native Java `endsWith` directly in Clojure:
(.endsWith "swapnil" "nil")
See http://clojure.org/java_interop for some more details.
You can then naturally compose this to get case insensitivity:
(.endsWith (clojure.string/lower-case "sWapNIL") "nil")
Problem
I have created a function to check whether or not my first string ends with a second string. In Java we have ready made method to check this, but in Clojure I failed to find such a method so I written custom function as follows: ``` (defn endWithFun [arg1 arg2] (= (subs arg1 (- (count arg1) (count arg2)) (count arg1)) arg2)) ``` Outputs: ``` > (endWithFun "swapnil" "nil") true > (endWithFun "swapnil" "nilu") false ``` This is working as expected. I want to know, is there a similar alternative? Also in my case, I compare case sensitively. I also want to ignore case sensitivity.