LoginLogin

Printing non left-alligned text?

Root / General / [.]

ShellyCreated:
With some code of course.
DEF PRINTR T$
 DIM I,P$[1],T0$=T$,L=!DISPLAY()*50+DISPLAY()*40
 WHILE LEN(T0$)DIV L
  FOR I=0 TO L-1:PUSH P$[LEN(P$)-1],SHIFT(T0$):NEXT I
  PUSH P$,""
 WEND
 P$[LEN(P$)-1]=" "*MAX(L-LEN(T0$),0)+T0$
 WHILE LEN(P$):PRINT SHIFT(P$):WEND
END
I can't test it atm. Does it work? Probably. Will someone come along and write some better code? Yes! Edit: Okay, after extensive editing I think it'll work. Oh, and by not centered and not left-aligned, I am assuming you mean right-aligned, unless you are not...? Probably a better version:
DEF PRINTR T$
 DIM Y%=CSRY,P$,T0$,L%=!DISPLAY()*50+DISPLAY()*40
 WHILE LEN(T0$)>.PUSH P$,SHIFT(T0$)
  IF LEN(P$)==L%THEN LOCATE.,Y%?P$P$=""INC Y%
 WEND
 UNSHIFT P$," "*(L%-LEN(P$))?P$LOCATE.,Y%+1
END

Unless I'm misunderstanding, you can just use FORMAT$() to right-align text to a certain width.
VAR W$="Right-align me"
PRINT FORMAT$("%25S", W$)
This will print W$ as though it had just enough leading spaces to be 25 characters wide, with the actual text at the end (or right side if you will.) For reference, the text console is 50 characters wide.

If the text is longer than 25 characters, this method fails.

If the text is longer than 25 characters, this method fails.
Of course, you can just change the width if you need to. Just an illustrative example.

This will cut off the text if it's longer:
PRINT FORMAT$("%25.25S", W$)