Skip to main content

Description

Pads the start (left side) of a string with a specified character until it reaches the desired length.

Syntax

Parameters

Returns

Type: string The padded string. If the original string is already longer than the target length, it is returned unchanged. Returns null if input is null.

Examples

Example 1: Basic Left Padding

Output:

Example 2: Formatting Numbers with Leading Zeros

Output:

Example 3: Aligning Text

Output:

Notes

  • Returns null if input is null
  • Converts numbers to strings automatically
  • Default padding character is a space
  • If string is already longer than target length, returns original string
  • Useful for formatting IDs, aligning columns, or creating fixed-width output

See Also

Frequently Asked Questions

The original string is returned unchanged — no truncation occurs.
The default padding character is a space ' ' if no padChar argument is provided.