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}/, "")
import "strings"
t := strings.TrimPrefix(s, p)
uses StrUtils;
if AnsiStartsStr(p, s) then 
  t := copy(s, length(p)+1, length(s)-length(p))
else
  s := t;

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

Idiom created by

programming-idioms.org

Related idioms