count until predicate returns false

Jonathan M Davis jmdavisProg at gmx.com
Mon Aug 15 14:28:38 PDT 2011


On Monday, August 15, 2011 14:09 David Nadlinger wrote:
> On 8/15/11 11:00 PM, Jonathan M Davis wrote:
> > On Monday, August 15, 2011 12:53 Andrej Mitrovic wrote:
> >> This will print the count of whitespace chars in a line:
> >> 
> >> writeln(count!isWhite(line));
> >> 
> >> What I need is the count of whitspace chars until the first
> >> non-whitespace char is found, essentially I need a "countWhile"
> >> template:
> >> 
> >> writeln(countWhile!isWhite(line));
> >> 
> >> Can I do this with existing templates somehow?
> > 
> > writeln(count!(not!isWhite)(line));
> > 
> > - Jonathan M Davis
> 
> Wouln't this rather count the total number of whitespace characters in a
> line? Did you mean writeln(countUntil!(not!isWhite)(line))?

You're right. I misunderstood what count did.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list