Logo

Programming-Idioms

  • Java
  • Lua

Idiom #97 Check string suffix

Set boolean b to true if string s ends with string suffix, false otherwise.

Are the last characters of s equal to this suffix?
b = s:sub(-string.len(suffix)) == suffix

Implementation for non static suffix
boolean b = s.endsWith(suffix);
(require '[clojure.string :as str])
(let [b (str/ends-with? s suffix)]
   ; ...  
 )

New implementation...
< >
programming-idioms.org