On Mon, 09 Jun 2014 07:04:11 -0400, Chris <wend...@tcd.ie> wrote:

On Monday, 9 June 2014 at 10:54:09 UTC, monarch_dodra wrote:
On Monday, 9 June 2014 at 10:23:16 UTC, Chris wrote:

Ok, thanks. I'll keep that in mind for the next version.

Seems to me to also work with 2.065 and 2.064.

 From the library reference:

assert(equal(splitter("hello  world", ' '), [ "hello", "", "world" ]));

Note the 2 spaces between hello and world

and

"If a range with one separator is given, the result is a range with two empty elements."

Right, it allows you to distinguish cases where the range starts or ends with the separator.

My problem was that if I have input like

auto word = "bla-";

it will return parts.data.length == 2, so I would have to check parts.data[1] != "". This is too awkward. I just want the parts of the word, i.e.

length == 2 // grab [0] grab [1]
length == 1 // grab [0] (no second part, as in "bla-")
length > 2 // do something else

One thing you could do is strip any leading or trailing hyphens:


assert("-bla-".chomp("-").chompPrefix("-").split('-').length == 1);

Just looked at std.string for a strip function that allows custom character strippage, but apparently not there. The above is quite awkward.

-Steve
  • splitter for strings Chris via Digitalmars-d-learn
    • Re: splitter for strings bearophile via Digitalmars-d-learn
      • Re: splitter for str... Chris via Digitalmars-d-learn
        • Re: splitter for... monarch_dodra via Digitalmars-d-learn
          • Re: splitter... Chris via Digitalmars-d-learn
            • Re: spl... monarch_dodra via Digitalmars-d-learn
              • Re:... Chris via Digitalmars-d-learn
                • ... monarch_dodra via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
            • Re: spl... Steven Schveighoffer via Digitalmars-d-learn
              • Re:... Chris via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
                • ... monarch_dodra via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
                • ... monarch_dodra via Digitalmars-d-learn
                • ... Chris via Digitalmars-d-learn
              • Re:... monarch_dodra via Digitalmars-d-learn
                • ... Steven Schveighoffer via Digitalmars-d-learn
                • ... monarch_dodra via Digitalmars-d-learn

Reply via email to