Logo

Programming-Idioms

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

Idiom #168 Trim suffix

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

local t = s:gsub(w.."$", "")

The $ attached to w matches the end of the string s and is replaced by an empty string.
using System;
string t = s.TrimEnd(w);

New implementation...
programming-idioms.org