Align columns: Difference between revisions
Content added Content deleted
(Add Easylang) |
|||
Line 3,272: | Line 3,272: | ||
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.</syntaxhighlight> |
justified, right justified, or center justified within its column.</syntaxhighlight> |
||
=={{header|EasyLang}}== |
|||
{{trans|AWK}} |
|||
<syntaxhighlight lang=easylang> |
|||
global width inp$[] . |
|||
proc read . . |
|||
repeat |
|||
inp$ = input |
|||
until inp$ = "" |
|||
inp$[] &= inp$ |
|||
ar$[] = strsplit inp$ "$" |
|||
for s$ in ar$[] |
|||
width = higher width len s$ |
|||
. |
|||
. |
|||
. |
|||
call read |
|||
# |
|||
proc out mode . . |
|||
for inp$ in inp$[] |
|||
ar$[] = strsplit inp$ "$" |
|||
for s$ in ar$[] |
|||
spc = width - len s$ + 1 |
|||
if mode = 1 |
|||
write s$ |
|||
for i to spc |
|||
write " " |
|||
. |
|||
elif mode = 2 |
|||
for i to spc |
|||
write " " |
|||
. |
|||
write s$ |
|||
elif mode = 3 |
|||
for i to spc div 2 |
|||
write " " |
|||
. |
|||
write s$ |
|||
for i to spc - spc div 2 |
|||
write " " |
|||
. |
|||
. |
|||
. |
|||
print "" |
|||
. |
|||
. |
|||
call out 1 |
|||
print "" |
|||
call out 2 |
|||
print "" |
|||
call out 3 |
|||
# |
|||
input_data |
|||
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. |
|||
</syntaxhighlight> |
|||
=={{header|Elixir}}== |
=={{header|Elixir}}== |