Create string t consisting of string s with its suffix w removed (if s ends with w).
import static java.util.regex.Pattern.quote;
String t = s.replaceAll(quote(w) + '$', "");
int i = s.lastIndexOf(w), m = s.length(), n = w.length(); t = i == m - n ? s.substring(0, i) : s;
String t = s; int index = s.lastIndexOf(w); if (index + w.length() == s.length()) { t = s.substring(0, index); }
using System;
string t = s.TrimEnd(w);
import std.string;
string t = s.chomp(w);
i = index(s,w,back=.true.) - 1 if (i == len(s) - len(w) ) then allocate (t, source=s(:i)) else allocate (t, source=s) end if
import "strings"
t := strings.TrimSuffix(s, w)
import Data.List (isSuffixOf)
t :: String t = if w `isSuffixOf` s then take (length s - length w) else s
const t = s.endsWith(w) ? s.slice(0, -w.length) : s
local t = s:gsub(w.."$", "")
preg_replace("/{$w}$/u", '', $s);
uses StrUtils;
if AnsiEndsStr(w, s) then t := copy(s, 1, length(s) - length(w)) else t :=s;
if (length $s == rindex($s, $w) + length $w) { my $t = substr $s, 0, rindex $s, $w; }
t = s.removesuffix(w)
t = s.delete_suffix(w)
t = s.sub(/#{w}\z/, "")
let t = s.trim_end_matches(w);
let t = s.strip_suffix(w).unwrap_or(s);
No security, no password. Other people might choose the same nickname.