https://issues.dlang.org/show_bug.cgi?id=20184
Jon Degenhardt <[email protected]> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |[email protected] | |m --- Comment #1 from Jon Degenhardt <[email protected]> --- 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" ])); assert("a|bc|def".splitter('|').take(1).equal([ "a" ])); 'splitter' (from std.algorithm) is a lazy version of 'split', which is eager. It produces an input range. 'take' (from std.range) takes the first N elements from an input range. 'take' is also lazy. To convert it to a fully realized array similar to the result of 'split' use 'array' (from std.array) or another range "eager" range algorithm. e.g. auto x = "a|bc|def".splitter('|').take(2).array; assert(x.length == 2); assert (x[0] == "a"); assert (x[1] == "bc"); --
