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

Idiom #167 Trim prefix

Create string t consisting of string s with its prefix p removed (if s starts with p).

t = s.sub(/\A#{p}/, "")
t = s.delete_prefix(p)
import std.string;
string t = s.chompPrefix(p);
import "strings"
t := strings.TrimPrefix(s, p)
uses StrUtils;
if AnsiStartsStr(p, s) then 
  t := copy(s, length(p)+1, length(s)-length(p))
  s := t;

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

Idiom created by

Related idioms