Align columns: Difference between revisions
Content added Content deleted
(→{{header|R}}: Incorrect. Alignment in the rightmost columns is wrong.) |
(added Ursala) |
||
Line 1,129: | Line 1,129: | ||
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|Ursala}}== |
|||
The algorithm is to lex the text to a list of lists of strings assuming $ as a separator, |
|||
then pad the lists out to the length of the maximum length list, transpose, |
|||
do the same with each column, and transpose again. For left justification, |
|||
nothing further but concatenation is needed. For right justifications, each word's string |
|||
of trailing blanks is moved to the beginning, and for center justification, the |
|||
trailing blanks are divided equally between the beginning and end of each word. |
|||
<lang Ursala> |
|||
#import std |
|||
text = |
|||
-[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.]- |
|||
pad = sep`$*; @FS ~&rSSSK7+ (zipp` ^*D\~& leql$^)*rSSK7+ zipp0^*D/leql$^ ~& |
|||
just_left = mat` *+ pad |
|||
just_right = mat` *+ pad; ==` ~-rlT** |
|||
just_center = mat` *+ pad; ==` ~-rK30PlrK31PTT** |
|||
#show+ |
|||
main = mat0 <.just_left,just_center,just_right> text |
|||
</lang> |
|||
output: |
|||
<pre style="height:17ex;overflow:scroll"> |
|||
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. |
|||
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. |
|||
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. |
|||
</pre> |
|||
=={{header|Vedit macro language}}== |
=={{header|Vedit macro language}}== |