Skip to content

PAD

Justify and Pad String

This string function returns a centered, left- or right-justified string padded to a specific length with the specified pad character.

PAD (string-value, numeric-value [,pad-option] [,pad-value]
[,ERR=line-ref|,ERC=error-code])
string-value
is any valid string.
numeric-value
is a positive integer that specifies the length of the string to build.
pad-option
is any valid string whose first character specifies whether to left-justify, right-justify, or center the string data. The value "L" justifies the given string to the left and appends pad characters; the value "R" justifies the given string to the right and inserts pad characters before the string; the value "C" centers the given string and inserts pad characters before the string. The default is to left-justify the string.
pad-value
is any valid string whose first character is used to fill the returning string to the specified length. The default is the space character.
line-ref
is the program line number or label to branch to if an error is produced by this function.
error-code
is a programmer-defined error code. Valid values are positive or negative whole numbers.

This function is generally available starting with release level 8.1.

The centering option is generally available starting with release 8.3.0.

If given string is a null string, and then this function returns a string at the specified size containing only the pad characters.

If numeric-value is zero, then this function returns a null string.

If numeric-value is smaller than the size of the given string, then the returning string is truncated to the specified size.

If numeric-value is not an integer, an ERR=41 results.

If pad-option and pad-value are both specified, any character other than “R” or “C” in the pad-option is treated as an “L” (the default).

B$ = PAD("TEST",10)

B$ receives “TEST “.

B$ = PAD("TEST",10,"M")

B$ receives “TESTMMMMMM”.

LET A$ = "TEST"
B$ = PAD(A$,10,"R")

B$ receives “ TEST”.

B$ = PAD("TEST",10,"R","M")

B$ receives “MMMMMMTEST”.

B$ = PAD("TEST",3)

B$ receives “TES”.

B$ = PAD("",10)

B$ receives 10 spaces.

B$=PAD("TEST",10,"C","-")

B$ receives the value “—TEST—”.

DIM string, DIM string array directives DIM, and =ALL functions

From the Thoroughbred Basic Language Reference, Volume II: F–Q, version 8.9.1. Open this page in the PDF