create fixed length string of characters

Olivier Pisano olivier.pisano at laposte.net
Fri Aug 16 06:45:35 UTC 2024


On Friday, 16 August 2024 at 06:15:18 UTC, Bruce wrote:
> Is there an easy way to create a 60 character string in D?
> Like in Python...
> ul = '-'*60

You can use the repeat() function in std.range to create a range 
of N consecutive elements.
If you need to assign this range to a string, you'll have to use 
the array() function.

import std.range;
import std.stdio;

void main()
{

     string s = '-'.repeat(60).array;
     writeln(s);
}




More information about the Digitalmars-d-learn mailing list