Name

padleft — prefix a string up to a specified length

Synopsis

string padleft( str,  
  length,  
  padding);  
string   str;
int   length;
string   padding ;

Description

If strlen(str) > length then str is returned unaltered. Otherwise the string padding is continuously concatenated to the front of str until it is exactly length characters long. Note that this may mean that the final concatenation of padding may be truncated.

If the optional parameter padding is omitted then the string " " (a single space) is used as padding.

If padding has zero length or length < 0 then the result is undefined, probably a run time error.

Example 42. padleft Example

padleft("Hello", 10);           // = "     Hello"
padleft("Boo!, 10, "-x-");      // = "-x--x-Boo!"
padleft("Trunc", 10, "-x-");    // = "-x--xTrunc"

See Also

This function complements the pad() function.