Align columns: Difference between revisions

no edit summary
(Add Jsish)
No edit summary
Line 2,843:
Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column.</pre>
 
=={{header|Harbour}}==
 
<lang visualfoxpro>
PROCEDURE Main()
LOCAL a := { "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." }
LOCAL e, nMax
// remove trailing dollars
AEval( a, {|e,n| Iif( Right(e,1)=="$", a[n] := hb_StrShrink( e, 1 ), NIL ) } )
// find max word length
nMax := 0
AEval( a, {|e| AEval( hb_Atokens( e, "$"), {|i| nMax := Max( nMax, Len(i) )} ) } )
nMax++
// start printing, padding words as needed
?
? "----Left aligned columns----"
FOR EACH e IN a
?
AEval( hb_Atokens( e, "$"), {|i| QQout( PadR(i, nMax) )} )
NEXT
?
? "----Center aligned columns----"
FOR EACH e IN a
?
AEval( hb_Atokens( e, "$"), {|i| QQout( PadC(i, nMax) )} )
NEXT
?
? "----Right aligned columns----"
FOR EACH e IN a
?
AEval( hb_Atokens( e, "$"), {|i| QQout( PadL(i, nMax) )} )
NEXT
RETURN
</lang>
Output:
<lang text>----Left aligned columns----
----Left aligned columns----
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.
 
----Center aligned columns----
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.
 
----Right aligned columns----
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.</lang>
 
=={{header|Haskell}}==
Anonymous user