This language bar is your friend. Select your favorite languages!

Idiom #97 Check string suffix

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

Illustration
import std.algorithm.searching;
b = s.endsWith(suffix);
var b = s.endsWith(suffix);
String.ends_with?(s, suffix)
import "strings"
b := strings.HasSuffix(s, suffix)
import Data.Text
b = isSuffixOf suffix s
var b = s.endsWith(suffix);
boolean b = s.endsWith(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)

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

programming-idioms.org

Related idioms