Fork me on GitHub
#beginners
<
2020-05-31
>
robertaguilerajr19: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.

andy.fingerhut19:05:03

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

michael81919:05:01

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

robertaguilerajr19: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?")

michael81919:05:31

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

michael81919:05:49

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

robertaguilerajr19:05:18

Ahhhh, dangit. That was it. Thanks lot.