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

Idiom #168 Trim suffix

Create string t consisting of string s with its suffix w removed (if s ends with w).

import std.string;
string t = s.chomp(w);
import "strings"
t := strings.TrimSuffix(s, w)
uses StrUtils;
if AnsiEndsStr(w, s) then
  t := copy(s, 1, length(s) - length(w))
  t :=s;
t = s.rsplit(w, 1)[0]
t = s.sub(/#{w}\z/, "")
t = s.delete_suffix(w)

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

Idiom created by

Related idioms