Building a string from n chars

Meta via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Wed Sep 3 13:23:16 PDT 2014


On Wednesday, 3 September 2014 at 20:20:09 UTC, Meta wrote:
> On Wednesday, 3 September 2014 at 19:43:26 UTC, Nordlöw wrote:
>> Is there a simpler way to way to
>>
>> s ~= repeat('*', n).array.to!string;
>>
>> if s has to be of type string?
>
> Does this work?
>
> s ~= "*".replicate(n);

Sorry, I should qualify that replicate is from std.array. You can 
also just do either `s ~= repeat('*', n).array` OR `s ~= 
repeat('*', n).to!string`. Either should work.


More information about the Digitalmars-d-learn mailing list