- String manipulation functions
- cstr_escape()
- json
.escape() - regsub()
- regsuball()
- std
.anystr2ip() - std
.atof() - std
.atoi() - std
.ip() - std
.ip2str() - std
.prefixof() - std
.str2ip() - std
.strlen() - std
.strpad() - std
.strrep() - std
.strrev() - std
.strstr() - std
.strtof() - std
.strtol() - std
.suffixof() - std
.tolower() - std
.toupper() - substr()
- urldecode()
- urlencode()
- utf8
.codepoint_count() - utf8
.is_valid() - utf8
.strpad() - utf8
.substr()
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