Align columns: Difference between revisions

Simpler D entry
(Updated D entry)
(Simpler D entry)
Line 702:
 
=={{header|D}}==
<lang d>import std.stdio, std.string, std.algorithm, std.array, std.typetuple;
 
void main() {
Line 719:
maxWidths[i] = max(maxWidths.get(i, 0), word.length);
 
foreach (i, just; TypeTuple!(leftJustify, center, rightJustify)) {
writeln(["Left", "Center", "Right"][i],
" column-aligned output:\n");
foreach (line; data) {
foreach (j, word; line)
Line 727 ⟶ 725:
writeln();
}
"- ".replicate(52).writeln();
}
}</lang>
{{out}}
<pre>Given a txt file of many lines, where fields within a line
<pre>Left column-aligned output:
 
Given a txt file of many lines, where fields within a line
are delineated by a single 'dollar' character, write a program
that aligns each column of fields by ensuring that words in each
Line 739 ⟶ 733:
Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Center column-aligned output:
 
Given a txt file of many lines, where fields within a line
are delineated by a single 'dollar' character, write a program
Line 748 ⟶ 739:
Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Right column-aligned output:
 
Given a txt file of many lines, where fields within a line
are delineated by a single 'dollar' character, write a program
Line 756 ⟶ 744:
column are separated by at least one space.
Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column. </pre>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - </pre>
 
=={{header|Delphi}}==