Dnia 30-07-2010 o 17:24:41 dcoder <dco...@devnull.com> napisał(a):

Is there anyway in D to convenient fill a string variable with a char say X times?

If you need to only print, you can:

import std.stdio;
import std.range;

void main() {
    foreach (c; take(repeat('-'), 5))
        write(c);
}

I know, I know, you said *convenient* ;) I heard write(ln) is to print arbitrary ranges, so this'd come down to:

writeln(take(repeat('-'), 5));

and if universal call syntax worked correctly then even this would be possible:

writeln('-'.repeat.take(5));

much easier to type.

BTW, I stumbled on this when crafting the example:
http://d.puremagic.com/issues/show_bug.cgi?id=4537


Tomek

Reply via email to