strip and dmd 2.056

Jonathan M Davis jmdavisProg at gmx.com
Sat Dec 10 14:23:48 PST 2011


On Saturday, December 10, 2011 16:18:22 bearophile wrote:
> bioinfornatics:
> > it seem now we can not use this:
> >  ";;;;;;blah".stripLeft(";");
> >  Error: template std.string.stripl(String) cannot deduce template
> > 
> > function from argument types !()(string,string)
> > 
> > 
> > they are another way ?
> 
> In Python str.lstrip accepts an optional argument:
> >>> ";;;;;;blah".lstrip(";")
> 
> 'blah'
> 
> 
> But I think with the current Phobos you need to use something like this:
> 
> import std.stdio, std.string;
> void main() {
>     string s = ";;;;;;blah";
>     munch(s, ";");
>     writeln(s);
> }

None of the strip or split functions in Phobos deal with anything other than 
whitespace. splitter is more general, but there is no stripper (which would 
arguably be a horrible name for a function anyway). However, that's 
essentially what find does, albeit with the predicate effectively being 
reversed. e.g.

find!"a != ';'"(";;;;;blah");

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list