Fork me on GitHub
Rob Aguilera19:05:13

Hi guys, I'm stuck on something simple. I'm trying to find if the last character of a string ends in a "?". I tried ends-with? but that doesn't seem to produce the result I want. I thought maybe I could split a string like in JavaScript "Hello".split(-1) where I grab the last character of a string and then check what the value is but having trouble with that.


Do you have an example where ends-with? does not produce the result you want?

Michael W19:05:01

(= \? (last "testing?"))

Rob Aguilera19:05:12

Sure probably should have led with that 🙂 (ends-with? "?" "Hello?") ;; => false . Not sure if this could be the issue but in the namespace I'm requiring string and aliasing it so the code actually looks something like this:

(ns bob
  (:require [clojure.string :as s]))
(s/ends-with? "?" "Hello?")

Michael W19:05:31

You have the args backwards. It's string then substring

Michael W19:05:49

(clojure.string/ends-with? "Hello?" "?")

Rob Aguilera19:05:18

Ahhhh, dangit. That was it. Thanks lot.