How do I match a dash with munch?

Jarrett Billingsley jarrett.billingsley at gmail.com
Thu Jan 15 06:30:51 PST 2009


On Thu, Jan 15, 2009 at 8:55 AM, Simen Kjaeraas <simen.kjaras at gmail.com> wrote:
> munch("bar-baz", "-");
>
> returns "". Is there a way to do this apart from writing my own function?

I think you've got the behavior of munch backwards.  It will eat any
characters that _are_ in the pattern string.  Since 'b' is not in the
string "-", it returns immediately, since it didn't munch anything.

If you're looking for something to split up a string into tokens, you
could either use find or split; the former could be used to slice the
string one piece at a time, and the latter does it all at once at the
expense of allocating a new array to put the slices in.


More information about the Digitalmars-d-learn mailing list