digitalmars.D.learn - std.algorithm.splitter improovement?
- seany (9/9) Dec 14 2013 the std.algorithm.splitter returns a blank or null (eg a null
- Peter Alexander (3/12) Dec 14 2013 Just filter out the empty ranges:
- bearophile (4/6) Dec 14 2013 It's a bug.
- Marco Leise (6/15) Dec 14 2013 Not at all, the documentation explicitly states:
- bearophile (16/19) Dec 14 2013 I didn't see the ' ' in the OP code, sorry.
- Dmitry Olshansky (5/24) Dec 14 2013 Yup, there are 2 splitters - one that uses explicit separator and one
- Marco Leise (9/38) Dec 14 2013 Somehow I cannot say this makes me happy. I totally thought
- seany (6/42) Dec 15 2013 I was using, as I said, std.algorithm.splitter, and I did not
the std.algorithm.splitter returns a blank or null (eg a null string "") between two consecuting delimeters. for example, splitting "hello world" (two spaces between words) will return ["hello" , "", "world"] is there an improoved version of it, which wont return such a blank/null when multiple delimeters are found consecutively? (i tried to search the tango for d2, but i was not successful, should there be one like this already, it must have escaped my sight)
Dec 14 2013
On Saturday, 14 December 2013 at 16:00:06 UTC, seany wrote:the std.algorithm.splitter returns a blank or null (eg a null string "") between two consecuting delimeters. for example, splitting "hello world" (two spaces between words) will return ["hello" , "", "world"] is there an improoved version of it, which wont return such a blank/null when multiple delimeters are found consecutively? (i tried to search the tango for d2, but i was not successful, should there be one like this already, it must have escaped my sight)Just filter out the empty ranges: r.splitter().filter!(x => !x.empty)
Dec 14 2013
seany:for example, splitting "hello world" (two spaces between words) will return ["hello" , "", "world"]It's a bug. Bye, bearophile
Dec 14 2013
Am Sat, 14 Dec 2013 17:41:22 +0100 schrieb "bearophile" <bearophileHUGS lycos.com>:seany:Not at all, the documentation explicitly states: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ])); -- Marcofor example, splitting "hello world" (two spaces between words) will return ["hello" , "", "world"]It's a bug. Bye, bearophile
Dec 14 2013
Marco Leise:Not at all, the documentation explicitly states: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));I didn't see the ' ' in the OP code, sorry. A test: void main() { import std.stdio, std.string, std.algorithm; auto s = "hello world"; s.split().writeln; std.array.splitter(s).writeln; s.splitter(' ').writeln; } The output seems OK: ["hello", "world"] ["hello", "world"] ["hello", "", "world"] Bye, bearophile
Dec 14 2013
14-Dec-2013 21:20, bearophile пишет:Marco Leise:Yup, there are 2 splitters - one that uses explicit separator and one that uses predicate. AFAIK the default predicate is std.uni.isWhite.Not at all, the documentation explicitly states: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));I didn't see the ' ' in the OP code, sorry. A test: void main() { import std.stdio, std.string, std.algorithm; auto s = "hello world"; s.split().writeln; std.array.splitter(s).writeln; s.splitter(' ').writeln; } The output seems OK:["hello", "world"] ["hello", "world"] ["hello", "", "world"] Bye, bearophile-- Dmitry Olshansky
Dec 14 2013
Am Sat, 14 Dec 2013 18:20:13 +0100 schrieb "bearophile" <bearophileHUGS lycos.com>:Marco Leise:Somehow I cannot say this makes me happy. I totally thought there was only one splitter and it has to be used with a delimiter. You are right that the OP didn't say which version he used. The result made it clear in the end. So the solution to this is "use the other splitter". -- MarcoNot at all, the documentation explicitly states: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));I didn't see the ' ' in the OP code, sorry. A test: void main() { import std.stdio, std.string, std.algorithm; auto s = "hello world"; s.split().writeln; std.array.splitter(s).writeln; s.splitter(' ').writeln; } The output seems OK: ["hello", "world"] ["hello", "world"] ["hello", "", "world"] Bye, bearophile
Dec 14 2013
On Sunday, 15 December 2013 at 01:25:39 UTC, Marco Leise wrote:Am Sat, 14 Dec 2013 18:20:13 +0100 schrieb "bearophile" <bearophileHUGS lycos.com>:I was using, as I said, std.algorithm.splitter, and I did not know that it could be called without a delimeter. i always called it like std.algorithm.splitter("hello world", ' '); //two spaces in array And that is giving me one empty element.Marco Leise:Somehow I cannot say this makes me happy. I totally thought there was only one splitter and it has to be used with a delimiter. You are right that the OP didn't say which version he used. The result made it clear in the end. So the solution to this is "use the other splitter".Not at all, the documentation explicitly states: assert(equal(splitter("hello world", ' '), [ "hello", "", "world" ]));I didn't see the ' ' in the OP code, sorry. A test: void main() { import std.stdio, std.string, std.algorithm; auto s = "hello world"; s.split().writeln; std.array.splitter(s).writeln; s.splitter(' ').writeln; } The output seems OK: ["hello", "world"] ["hello", "world"] ["hello", "", "world"] Bye, bearophile
Dec 15 2013