splitter for strings

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Jun 9 07:47:45 PDT 2014


On Mon, 09 Jun 2014 10:39:39 -0400, Chris <wendlec at tcd.ie> wrote:

> Atm, I have
>
> auto parts = appender!(string[]);
> w.splitter('-').filter!(a => !a.empty).copy(parts);
>
> Which looks more elegant and gives me what I want. IMO, the module that  
> handles the splitting of hyphenated words should be able to deal with  
> cases like "blah-" without the input being prepared in a certain way.

It's not mishandled. It's handled exactly as I would have expected. If  
"blah-" and "blah" result in the same thing, then how do you know the  
difference?

Stripping any possible leading or trailing hyphens is much more efficient  
than checking every single word to see if it's empty.

However, if you have an instance of "--", your solution will remove the  
extra empty string, whereas mine does not. Not sure if that's important.

-Steve


More information about the Digitalmars-d-learn mailing list