pad — pad a string up to a specified length


string pad( str,  
string   str;
int   length;
string   padding ;


If strlen(str) > length then str is returned unaltered. Otherwise the string padding is continuously concatenated to the end 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 41. pad Example

pad("Hello", 10);           // = "Hello     "
pad("Boo!, 10, "-x-");      // = "Boo!-x--x-"
pad("Trunc:", 10, "-x-");   // = "Trunc:-x--"

See Also

This function complements the padleft() function.