Skip to content

LeftPad ​

The LeftPad function returns the string S, left-justified within the output, and padded with the Ch character (on the right) if necessary, to make the output up to length of Len.

Declaration: Function LeftPad( S : string; Ch : Char; Len : Integer) : string;

Here are a few examples.

pascal
procedure OnMapEvent(var Value:Variant);
var
  Str1, Str2, Str3, Str4 : string;
begin
  Str1 := LeftPad('abc','1',5);                // returns 'abc11' - two padding characters added, leaving S left-justified
  Str2 := LeftPad('abcdef','1',10);            // returns 'abcdef1111' - four padding characters added
  Str3 := LeftPad('abc','1',2);                // returns 'abc' - no padding necessary (and no truncation)
  Str4 := LeftPad('This is a test','*',20);    // returns 'This is a test******' - 6 padding characters added
end;