std.strpad()

This function constructs a string containing the input string s padded out with pad to produce a string of the given width. The padding string pad is repeated as necessary and cut short when width is reached.

Note that width is given in bytes and this function will cut short paddings with multi-byte encodings.

Negative width left-justifies s by placing padding to the right. Positive width right-justifies s by placing padding to the left. If width is less than or equal to the length of s, then no padding is performed.

If pad is the empty string, then no padding is performed and the unmodified string s is returned.

Format

STRING
std.strpad(STRING s, INTEGER width, STRING pad)

Examples

1
set var.s = std.strpad("abc", -10, "-="); # produces "abc-=-=-=-"
1
set var.s = std.strpad("abc", 10, "-="); # produces "-=-=-=-abc"
1
2
3
4
declare local var.n INTEGER;
set var.n = std.strlen("abcd");
set var.n *= 3;
set var.s = std.strpad("", var.n, "abcd"); # repeat "abcd" three times