Skip to main content

RightPad

Function RightPad( S : string; Ch : Char; Len : Integer) : string

Example

procedure ScriptEvent(var Value: variant);
begin
Value := RightPad('42', '0', 5); // 00042
end;

Usage

RightPad prepends a chosen character until text reaches a minimum length, despite the function's right-padding name.

Parameters and return value

ItemMeaning
SText to retain. It is passed by value and not mutated.
ChCharacter prepended when padding is needed.
LenMinimum result length in Velox string code units.
ResultS unchanged when Len <= Length(S); otherwise left padding followed by S.

Important behavior and quirks

  • The name does not describe the implemented direction. For conventional space padding, PadL also pads on the left and PadR pads on the right.
  • LeftPad contains the reciprocal defect and appends its padding on the right.
  • The function never truncates text.
  • Zero or negative Len returns S unchanged.
  • A NUL padding character creates embedded NULs before the visible text and can confuse pointer-based consumers.
  • This is raw text padding. With a signed number such as -42, zero padding produces 00-42, not -0042.

Additional Technical Info

RightPad currently pads on the left. When S is shorter than Len, it returns StringOfChar(Ch, Len - Length(S)) + S. The public name is therefore directionally reversed.

The example is fictional and source-reviewed only.

Performance and concurrency

The helper allocates the padding and concatenated result. It reads no shared state.

External references

Created 2026-07-15