Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C++

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?
#include <string>
bool b = s.ends_with(suffix);

Requires C++20
return suffix.size() == s.size() - s.rfind(suffix);
(require '[clojure.string :as str])
(let [b (str/ends-with? s suffix)]
   ; ...  
 )

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