padl_padr

padl$(a$,width) and padr$(a$,width)
Two handy functions that pad string with spaces. (Will work nicely for printing columns in monospaced font (like Courier).) If width passed less then len(a$), it returns truncated a$ (first 'width' symbols). If you do not need such behavior, just get rid of outer left$(...,n) function.

BTW, >> roughly translates to >> (you cannot use TAB(n) outside of mainwin).

code format="lb" 'demo data Jack, "and", Jill, went, up, the, hill, "To fetch a pail of water.", "**" 'Short strings to be paddeed with spaces, long string to be cut by design.

print ">Source<";tab(30);">Pad right <    >  Pad left<" print "--"

while 1 read a$   if a$="**" then exit while print ">";a$;"<";tab(30);">";padr$(a$,10);"<    >";padl$(a$,10);"<"

wend

end

'functions '- 'adds spaces from the left until 'n' symbols 'if n<len(a$) returns left$(a$,n) function padl$(a$,n) padl$ = left$(space$(n-len(a$))+a$,n) end function

'adds spaces from the right until 'n' symbols 'if n<len(a$) returns left$(a$,n) function padr$(a$,n) padr$ = left$(a$+space$(n-len(a$)),n) end function code