LPad$

From BR Wiki
(Redirected from LPAD$)
Jump to navigation Jump to search
LPAD$(<string>$,<length>[,"<character>"])

The LPad$ internal function returns the string$, adding leading blanks to make it "length" characters long. If the string$ already has at least that many characters, no blanks are added.

Comments and Examples

10 LET A$ = "Right-justify"
20 LET B$ = "Right-edge"
30 PRINT LEN(A$),LEN(B$)
40 LET A$ = LPAD$(A$,13)
50 LET B$ = LPAD$(B$,13)
60 PRINT LEN(A$),LEN(B$)

The above example will print 10 and 13 from line 30, but will print 13 and 13 from line 60 after both strings have been left-padded with blanks.

An optional third parameter ("character") has been added to LPAD$ and RPAD$ to specify the character to be used for the padding (instead of blanks, which are still the default). The "character" parameter is limited to one character in length (error 410 will result if it is longer). Nulls and CHR$(0) are allowed.

See Also

Technical Considerations

  1. If the left padding is being done only to improve the output format, the CR format specification provides an alternative that executes faster, takes less time to code, and uses less program space.