Tabular IQ
Back to Function Index

RPAD()

Overview

RPAD() adds characters to the right side of a string until it reaches the specified length. If no characters are specified in the list, it adds spaces by default. This function is similar to LPAD(), but adds padding to the right side instead of the left side. RPAD() is useful for string formatting, alignment, and creating fixed-width strings.

Function Format

RPAD(string, length [, list])

Return Value

RPAD() returns a character string

Examples


// Padding with specific character
RPAD("APPLES", 10, ".") = "APPLES...."

// Padding with spaces (default)
RPAD("APPLES", 10) = "APPLES    "

// Truncating when length is less than string
RPAD("APPLES", 3) = "APP"

// Edge cases
RPAD("", 5, "*") = "*****"        // Empty string
RPAD("HELLO", 5) = "HELLO"        // Exact length
RPAD("HELLO", 0) = ""             // Zero length

Notes

  • Important behaviors:
    • Adds padding to the right side of the string
    • Uses spaces if no padding characters specified
    • Truncates string if length is less than string length
    • Uses first character from list for padding
    • Preserves original string content
  • Common use cases include:
    • String alignment
    • Fixed-width formatting
    • Visual formatting
    • Data presentation
    • Text padding
  • The function is useful for:
    • Right-side padding
    • String formatting
    • Data alignment
    • Visual consistency
  • Comparison with LPAD():
    • RPAD() adds padding to the right
    • LPAD() adds padding to the left
    • Both use same parameter structure
    • Both support custom padding characters

See Also