Logo

Programming-Idioms

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

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
(require '[clojure.string :as str])
(let [b (str/ends-with? s suffix)]
   ; ...  
 )
return suffix.size() == s.size() - s.rfind(suffix);
#include <string>
bool b = s.ends_with(suffix);
var _b = _s.EndsWith(_suffix);
bool b = s.EndsWith(suffix);
import std.algorithm.searching;
b = s.endsWith(suffix);
var b = s.endsWith(suffix);
b = String.ends_with?(s, suffix)
  b = (s(len(s)-len(suffix)+1:) == suffix)
import "strings"
b := strings.HasSuffix(s, suffix)
final b = s.endsWith(suffix)
import Data.Text
b = isSuffixOf suffix s
var b = s.endsWith(suffix);
boolean b = s.endsWith(suffix);
b = s.endsWith(suffix)

(defun check-suffix (str suf )
  (if (> (length suf) (length str )) nil (equalp (subseq str (- (length str) (length suf)) (length str )) suf )))

(setf b (check-suffix s suffix))
b = s:sub(-string.len(suffix)) == suffix
$b = (bool)preg_match("/{$suffix}$/", $s);
uses strutils;
b := AnsiEndsStr(suffix, s);
$b = $suffix eq substr($s, -length($suffix));
b = s.endswith(suffix)
b = s.end_with?(suffix)
let b = s.ends_with(suffix);
val b = s.endsWith(suffix)