Formatted output ranges

Dennis Ritchie via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Apr 17 07:44:35 PDT 2015


On Friday, 17 April 2015 at 09:25:43 UTC, Ivan Kazmenko wrote:
> On Saturday, 11 April 2015 at 22:45:39 UTC, Dennis Ritchie 
> wrote:
>> I also want to know whether it is possible to D somehow set 
>> the maximum width of the print string in characters?
>>
>> -----
>> void main() {
>> 	import std.stdio, std.range;
>> 	writefln(";; %(%s, %)).", iota(10, 1101));
>> }
>> -----
>>
>> For example, here's the code to Common Lisp which is given by 
>> the width of the line is 30 characters:
>> -----
>> (let ((a (loop :for i :from 10 :to 1100 :collect i)))
>> 	(format t "~%;;~{ ~<~%;; ~1,30:;~S~>~^,~}.~%" a))
>> -----
>> http://ideone.com/hGguge
>
> Looks like there's std.string.wrap to do that:
> http://forum.dlang.org/thread/mgqiji$727$1@digitalmars.com

Yes, it's a lot better but I did not get to concatenate the 
string ";;" in each paragraph:

-----
import std.conv, std.stdio, std.range, std.string;

void main() {

	auto a = iota(10, 1101).text;

	a = a[1 .. $ - 1], a ~= '.';

	writeln(wrap(a, 30));
}
-----
http://ideone.com/jsSbKj


More information about the Digitalmars-d-learn mailing list