put string[] into a appender without loop?

H. S. Teoh via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Sep 21 16:48:58 PDT 2014


On Sun, Sep 21, 2014 at 11:41:56PM +0000, AsmMan via Digitalmars-d-learn wrote:
> I'd like to copy an array string into a appender!string() but I can't
> see how to do this without loop myself over the string array. Is there
> a native function or should I write it myself?

Try this:

	import std.array : appender;
	import std.algorithm : joiner, copy;

	string[] arr = ["ab", "cd", "efg"];
	auto app = appender!string();
	arr.joiner.copy(app);
	assert(app.data == "abcdefg");


T

-- 
One reason that few people are aware there are programs running the internet is that they never crash in any significant way: the free software underlying the internet is reliable to the point of invisibility. -- Glyn Moody, from the article "Giving it all away"


More information about the Digitalmars-d-learn mailing list