Skip to content

Pad

See Also: String Functions, Append, Center, Left, Length, Trim

Purpose

Pad returns a string of specified length with spaces added to, or characters truncated from, the right of the input string as necessary.

Return Type

String

Syntax

(Pad({string-value}, {length}))

Where:

  • {string-value}: The source string to be padded with spaces.
  • {length}: The length to which {string-value} will be padded.

What It Does

Pad adds spaces to the right of {string-value} until the length of the string is equal to {length}.

Procedure Test
    String sFirstName sLastName
    Move "John" To sFirstName
    Move "Smith" To sLastName
    Showln (Pad(sFirstName, 10)) sLastName
End_Procedure

In the above example, the string "John······Smith" would be shown, where · represents a space character.

Notes

  • If {length} is less than the length of {string-value}, this function returns the value of type string truncated on the right to {length}, identically to the way the Left function works.
  • If {length} is 0, the function returns an empty string.
  • This function returns a value of type string. If the result of this function is moved to a variable of type other than string, its value is converted to the destination type.
  • If {string-value} is of type other than string, its value will be converted to a string for output.