Skip to main content

Right pad string (string.rpad)

Declaration

padded = string.rpad(text, len, pad)

Parameters

  • text
    string.
  • len
    integer. Target length after padding.
  • pad
    string, optional. Padding character(s). Default: space.

Returns

  • padded
    string.

Description

Right-pad text to length len using pad.
Available in versions after 2025-03-13

Example

nLog(string.rpad('ff',   6, '0'))  -- ff0000
nLog(string.rpad('100', 6, '0')) -- 100000
nLog(string.rpad('1234', 6, '0')) -- 123400
nLog(string.rpad('123', 6, 'xy')) -- 123xyx

Note: Uses function outside of this chapter: nLog