Skip to content

BASIC PAD Function

Curtis F Kaylor edited this page May 15, 2024 · 1 revision

PAD

TYPE: plusBASIC v0.22t string function


FORMAT: PAD$( string , length )

Action: Returns a string contain string padded with spaces to length length.

  • string is an expression that evaluates to a string
  • length is an expression that evaluates to an integer in the range -255 through 255.
  • If length is positive, spaces are added to the left.
    • If string is longer than length, the first length characters are returned.
  • If length is negative, spaces are added to the left.
    • If string is longer than length, the last length characters are returned.
  • If length is 0, an empty string is returned.

Examples:

PAD$("xyz",9)

Returns "xyz "

` PAD$("xyz",-10)

Returns " xyz"

` PAD$("xyz",1)

Returns "x"

` PAD$("xyz",-2)

Returns "yz"

` PAD$("xyz",0)

Returns ""


FORMAT: PAD$( string , length , char )

Action: As above, but the string is padded with char instead of spaces.

  • char is an expression that evaluates to either a string or an integer in the range 0 through 255.
    • If char is an integer, the string is padded with the corresponding ASCII character.
    • If char is a string, the first character is used as the pad character.
    • Illegal quantity results if char is an empty string.

Examples:

` PAD$("xyz",9,"!")

Returns "xyz!!!!!!"

` PAD$("xyz",-10,"@")

Returns "@@@@@@@xyz"

` PAD$("xyz",5,0)

Returns "xyz££"

` PAD$("xyz",-6,0)

Returns "£££xyz"

Clone this wiki locally