Skip to content

StringUtils.leftPad

Signature: StringUtils.leftPad(inputString, size, padString*)

Returns: String result - the left-padded String or original String if no padding is necessary, or null if inputString is null

Left pad the inputString with a space (default) or the optional padString.

Parameters

Type Name Description Default
String inputString the String to pad out, may be null
Integer size the size to pad to
String padString* (optional) the String to pad with ' '

Example

// Example: left pad a string to a fixed width.

StringUtils.leftPad(
    '321.00', // inputString
    10,       // size
    '0'       // padString (optional)
);            // 0000321.00

StringUtils.leftPad(
    '$4.24',    // inputString
    10          // size
    // padString omitted (defaults to space)
);  //      $4.24