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).

import qualified Data.Maybe as Maybe
import qualified Data.List as List
t = Maybe.fromMaybe s $ List.stripPrefix p s
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;
t = s[s.startswith(p) and len(p):]
t = s.delete_prefix(p)
t = s.sub(/\A#{p}/, "")
let t = s.trim_left_matches(p);

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

Idiom created by

Related idioms