std.algorithm.splitter improovement?

seany seany at uni-bonn.de
Sun Dec 15 23:41:46 PST 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 at lycos.com>:
>
>> 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
>
> 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".

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.


More information about the Digitalmars-d-learn mailing list