RosettaCodeData/Task/Align-columns/BaCon/align-columns.bacon

35 lines
1006 B
Plaintext

DECLARE in$[] = { "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." }
OPTION DELIM "$"
CONST items = 6
SUB Print_In_Columns(style)
' Find widest column
FOR y = 0 TO items-1
FOR x = 1 TO AMOUNT(in$[y])
IF LEN(TOKEN$(in$[y], x)) > max THEN max = LEN(TOKEN$(in$[y], x))
NEXT
NEXT
' Print aligned
FOR y = 0 TO items-1
FOR x = 1 TO AMOUNT(in$[y])
PRINT ALIGN$(TOKEN$(in$[y], x), max+1, style);
NEXT
PRINT
NEXT
PRINT
END SUB
Print_In_Columns(0)
Print_In_Columns(1)
Print_In_Columns(2)