[your code here]
H. S. Teoh
hsteoh at quickfur.ath.cx
Tue Apr 17 19:00:18 PDT 2012
// Wraps long lines in standard input.
// Demonstrates D's powerful array manipulation facility and generic
// algorithms.
import std.algorithm;
import std.array;
import std.range;
import std.stdio;
void main() {
int width = 80;
foreach (line; stdin.byLine()) {
while (line.length > width) {
// Find longest space-terminated prefix of line that
// fits in width, and wrap it there.
char[] fits = find(retro(line[0..width]), " ").source;
writeln(fits);
line = line[fits.length .. $];
}
writeln(line);
}
}
More information about the Digitalmars-d
mailing list