Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
39
Task/Align-columns/Run-BASIC/align-columns.basic
Normal file
39
Task/Align-columns/Run-BASIC/align-columns.basic
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
theString$ = "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."
|
||||
|
||||
x = shoTable(theString$,"left",6)
|
||||
x = shoTable(theString$,"right",6)
|
||||
x = shoTable(theString$,"center",6)
|
||||
end
|
||||
|
||||
FUNCTION shoTable(theString$,align$,across)
|
||||
print "------------ align:";align$;" -- across:";across;" ------------"
|
||||
dim siz(across)
|
||||
b$ = " "
|
||||
while word$(theString$,i+1,"$") <> ""
|
||||
siz(i mod across) = max(siz(i mod across),len(word$(theString$,i + 1,"$")))
|
||||
i = i + 1
|
||||
wend
|
||||
for i = 0 to across - 1
|
||||
siz(i) = siz(i) + 1
|
||||
if siz(i) and 1 then siz(i) = siz(i) + 1
|
||||
next i
|
||||
|
||||
i = 0
|
||||
a$ = word$(theString$,i+1,"$")
|
||||
while a$ <> ""
|
||||
s = siz(i mod across) - len(a$)
|
||||
if align$ = "right" then a$ = left$(b$,s);a$
|
||||
if align$ = "left" then a$ = a$;left$(b$,s)
|
||||
if align$ = "center" then a$ = left$(b$,int(s / 2));a$;left$(b$,int(s / 2) + (s and 1))
|
||||
print "|";a$;
|
||||
i = i + 1
|
||||
if i mod across = 0 then print "|"
|
||||
a$ = word$(theString$,i+1,"$")
|
||||
wend
|
||||
print
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue