Align columns: Difference between revisions
Content added Content deleted
Line 8,549: | Line 8,549: | ||
Further, allow for each word in a column to be either left |
Further, allow for each word in a column to be either left |
||
justified, right justified, or center justified within its column.</pre> |
justified, right justified, or center justified within its column.</pre> |
||
=={{header|Transd}}== |
|||
<lang scheme>#lang transd |
|||
MainModule : { |
|||
txt: |
|||
"Given$a$text$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$ |
|||
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.", |
|||
tabl: Table(), |
|||
n: 0, |
|||
colWidths: Vector<Int>(), |
|||
print: (λ centered Bool(false) |
|||
(for n in Seq(0 (num-rows tabl)) do |
|||
(with row (get-row tabl n) |
|||
(for m in Seq(0 (num-cols tabl)) do |
|||
(with wid (+ 1.0 (get colWidths @idx)) |
|||
word (get row m) wl 0.0 lef 0 |
|||
(if centered (= wl (size String(word))) (= lef (/ (- wid wl) 2.0)) |
|||
(textout width: lef "" width: wl word width: (- wid (+ wl lef)) "") |
|||
else |
|||
(textout width: wid (get row m))))) |
|||
(lout "")) |
|||
) |
|||
), |
|||
_start: (λ |
|||
(load-table tabl txt fieldSep: "$" :emptyEls) |
|||
(for i in Seq(0 (num-cols tabl)) do (= n 0) |
|||
(tsd-query tabl |
|||
reduce: [i] |
|||
as: [[String()]] |
|||
using: (λ (set n (max (size (get @row 0)) n)))) |
|||
(append colWidths n) |
|||
) |
|||
(textout :right "") (print) |
|||
(lout :left "") (print) |
|||
(lout "") (print true) |
|||
) |
|||
}</lang>{{out}} |
|||
<pre> |
|||
Given a text file of many lines, where fields within a line |
|||
are delineated by a single 'dollar' character, write a program a line |
|||
that aligns each column of fields by ensuring that words in each |
|||
column are separated by at least one space. that words in each |
|||
Further, allow for each word in a column to be either left |
|||
justified, right justified, or center justified within its column. be either left |
|||
Given a text file of many lines, where fields within a line |
|||
are delineated by a single 'dollar' character, write a program a line |
|||
that aligns each column of fields by ensuring that words in each |
|||
column are separated by at least one space. that words in each |
|||
Further, allow for each word in a column to be either left |
|||
justified, right justified, or center justified within its column. be either left |
|||
Given a text file of many lines, where fields within a line |
|||
are delineated by a single 'dollar' character, write a program a line |
|||
that aligns each column of fields by ensuring that words in each |
|||
column are separated by at least one space. that words in each |
|||
Further, allow for each word in a column to be either left |
|||
justified, right justified, or center justified within its column. be either left |
|||
</pre> |
|||
=={{header|TUSCRIPT}}== |
=={{header|TUSCRIPT}}== |