LPAD$ function

Purpose:

LPAD$ pads the left side of a string with spaces or an optional fill character.

Syntax:

RetStr = LPAD$(MainStr AS STRING, _
            MaxLength AS INTEGER  _
   [,OptionalFillChar AS INTEGER])

Return Value:

  • Data type: STRING
    RetStr Left padded MainStr.

Parameters:

  • Data type: STRING
    MainStr String to be left padded.
  • Data type: STRING
    MaxLength Combined length of MainStr and padding characters. If the length of MainStr is greater than or equal to MaxLength then MainStr is returned. No truncation takes place.
  • Data type: INTEGER
    OptionalFillChar [OPTIONAL] Windows Code Page code point integer. Default fill character is ASCII code point 32 (space).

Example 1:

DIM RetStr$

RetStr$ = LPAD$("123", 5)
PRINT RetStr$

RetStr$ = LPAD$("123", 5, 66)
PRINT RetStr$

Result:

  123
BB123

Example 2:

FOR INTEGER i = 1 TO 10
 ? LPAD$(STR$(i, 1), 3, ASC("0"))
NEXT

PAUSE

Result:

001
002
003
004
005
006
007
008
009
010

RPAD$ function

Purpose:

RPAD$ pads the right side of a string with spaces or an optional fill character.

Syntax:

RetStr = RPAD$(MainStr AS STRING, _
            MaxLength AS INTEGER  _
   [,OptionalFillChar AS INTEGER])

Return Value:

  • Data type: STRING
    RetStr Returned right padded MainStr.

Parameters:

  • Data type: STRING
    MainStr String to be right padded.
  • Data type: STRING
    MaxLength Combined length of MainStr and padding characters. If the length of MainStr is greater than or equal to MaxLength then MainStr is returned. No truncation takes place.
  • Data type: INTEGER
    OptionalFillChar [OPTIONAL] Windows Code Page code point integer. Default fill character is ASCII code point 32 (space).

Example:

DIM RetStr$

RetStr$ = RPAD$("123", 5)
PRINT RetStr$

RetStr$ = RPAD$("123", 5, 65)
PRINT RetStr$

Result:

123 
123AA

CPAD$ function

Purpose:

CPAD$ centers a string and pads the right and left sides of the centered string with spaces or an optional fill character to a specified maximum combined length of the string and padding characters.

Syntax:

RetStr = CPAD$(MainStr AS STRING, _
            MaxLength AS INTEGER  _
   [,OptionalFillChar AS INTEGER])

Return Value:

  • Data type: STRING
    RetStr Centered, padded MainStr.

Parameters:

  • Data type: STRING
    MainStr String to be centered and padded.
  • Data type: STRING
    MaxLength Combined length of MainStr and padding characters. If the length of MainStr$ is greater than MaxLength then MainStr is truncated to MaxLength.
  • Data type: INTEGER
    OptionalFillChar [OPTIONAL] Windows Code Page code point integer. Default fill character is ASCII code point 32 (space).

Example:

DIM A$, B$
DIM AS uint8_t LoopCount
FOR LoopCount = 65 TO 95 ' ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ 
 A$ = A$ + CHR$(LoopCount)
 B$ = CPAD$(A$, 26) ' Truncate everything after the letter 'Z' 
 PRINT B$
NEXT

Result:

            A
           AB
          ABC
          ABCD
         ABCDE
         ABCDEF
        ABCDEFG
        ABCDEFGH
       ABCDEFGHI
       ABCDEFGHIJ
      ABCDEFGHIJK
      ABCDEFGHIJKL
     ABCDEFGHIJKLM
     ABCDEFGHIJKLMN
    ABCDEFGHIJKLMNO
    ABCDEFGHIJKLMNOP
   ABCDEFGHIJKLMNOPQ
   ABCDEFGHIJKLMNOPQR
  ABCDEFGHIJKLMNOPQRS
  ABCDEFGHIJKLMNOPQRST
 ABCDEFGHIJKLMNOPQRSTU
 ABCDEFGHIJKLMNOPQRSTUV
ABCDEFGHIJKLMNOPQRSTUVW
ABCDEFGHIJKLMNOPQRSTUVWX
ABCDEFGHIJKLMNOPQRSTUVWXY
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ
ABCDEFGHIJKLMNOPQRSTUVWXYZ