What should I use for concat string into array in loop?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Tue Feb 13 02:12:51 UTC 2018


On Monday, February 12, 2018 17:56:45 H. S. Teoh via Digitalmars-d-learn 
wrote:
> On Tue, Feb 13, 2018 at 01:58:42AM +0000, Marc via Digitalmars-d-learn 
wrote:
> > appender doesn't support string[] so in such case:
> Why not? This seems to work:
>
>   import std.array;
>   import std.stdio;
>   void main() {
>       auto app = appender!(string[]);
>       foreach (i; 0 .. 1000) {
>           app.put("abc");
>       }
>       writeln(app.data);
>   }

LOL. I read his message too quickly and missed that he had problem with
appender and told him about appender and some alternatives.

I assume that his problem is that he didn't use parens. If he tried
appender!string[], then it's not going to work, because the [] ends up being
associated with the result of appender!string instead of being associated
with string and the passed to appender.

- Jonathan M Davis



More information about the Digitalmars-d-learn mailing list