[Issue 20184] String maxsplit

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Sep 1 20:24:46 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=20184

--- Comment #2 from svnpenn at gmail.com ---
(In reply to Jon Degenhardt from comment #1)
> This can be achieved using 'splitter' and 'take' or another range iteration
> algorithm that limits the number of candidates selected.
> 
> e.g.
> 
> assert("a|bc|def".splitter('|').take(4).equal([ "a", "bc", "def" ]));
> assert("a|bc|def".splitter('|').take(3).equal([ "a", "bc", "def" ]));
> assert("a|bc|def".splitter('|').take(2).equal([ "a", "bc" ]));

It seems you have a profound misunderstand of what split limiting is. Here is a
result with Python:

    >>> 'one two three'.split(maxsplit = 1)
    ['one', 'two three']

as you can see, it doesnt discard any part of the original input, instead it
stops splitting after the specified amount, and puts the rest of the string as
the final element.

--


More information about the Digitalmars-d-bugs mailing list