Available in all subroutines.

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.


set var.s = std.strpad("abc", -10, "-="); # produces "abc-=-=-=-"
set var.s = std.strpad("abc", 10, "-="); # produces "-=-=-=-abc"

Repeating a string:

declare local var.s STRING;
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

User contributed notes

We welcome comments that add use cases, ideas, tips, and caveats. All comments will be moderated before publication. To post support questions, visit our support center and we'll find you the help you need.