Thread overview
strip and dmd 2.056
Dec 10, 2011
bioinfornatics
Dec 10, 2011
bearophile
Dec 10, 2011
Jonathan M Davis
December 10, 2011
dear,
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 ?

December 10, 2011
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);
}

Bye,
bearophile
December 10, 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