digitalmars.D.learn - How do I match a dash with munch?
- Simen Kjaeraas (4/4) Jan 15 2009 munch("bar-baz", "-");
- Jarrett Billingsley (8/10) Jan 15 2009 I think you've got the behavior of munch backwards. It will eat any
- Simen Kjaeraas (11/24) Jan 15 2009 Sorry, it seems I ferked up a bit there, yes (I did not in the code
munch("bar-baz", "-"); returns "". Is there a way to do this apart from writing my own function? -- Simen
Jan 15 2009
On Thu, Jan 15, 2009 at 8:55 AM, Simen Kjaeraas <simen.kjaras 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.
Jan 15 2009
On Thu, 15 Jan 2009 15:30:51 +0100, Jarrett Billingsley <jarrett.billingsley gmail.com> wrote:On Thu, Jan 15, 2009 at 8:55 AM, Simen Kjaeraas <simen.kjaras gmail.com> wrote: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. -- Simenmunch("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.
Jan 15 2009