Skip to main content

Left pad string (string.lpad)

Declaration

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

Parameters

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

Returns

  • padded
    string.

Description

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

Example

nLog(string.lpad('ff',   6, '0'))  -- 0000ff
nLog(string.lpad('100', 6, '0')) -- 000100
nLog(string.lpad('1234', 6, '0')) -- 001234
nLog(string.lpad('123', 6, 'xy')) -- xyx123

Note: Uses function outside of this chapter: nLog