How do I match a dash with munch?
Simen Kjaeraas
simen.kjaras at gmail.com
Thu Jan 15 06:48:46 PST 2009
On Thu, 15 Jan 2009 15:30:51 +0100, Jarrett Billingsley
<jarrett.billingsley at gmail.com> wrote:
> 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.
Sorry, it seems I ferked up a bit there, yes (I did not in the code
in which I intended to use it). And yes, I certainly could use split,
I just wanted to use munch.
Example of what I wanted:
munch("1 + 3", "0123456789+-*")`;
I managed to fix it, though. Just put '-' as the first character of the
string.
--
Simen
More information about the Digitalmars-d-learn
mailing list