pad
characters at the given side
(s) of each string
so that each output string consists of at least min_length
code points.
This function may be used to center or left/right-align each string.stri_pad_both(str, min_length = floor(0.9 * getOption("width")), pad = " ")stri_pad_left(str, min_length = floor(0.9 * getOption("width")), pad = " ")
stri_pad_right(str, min_length = floor(0.9 * getOption("width")), pad = " ")
stri_pad(str, min_length = floor(0.9 * getOption("width")), side = c("left",
"right", "both"), pad = " ")
stri_pad
only] single character string;
sides on which padding character is added
(left
, right
, or both
)str
, min_length
, and pad
.
Each string in pad
should consist of exactly one code point.stri_pad
is a convenience function, which dispatches
control to stri_pad_*
. Unless you are very lazy, do not use it:
it is a little bit slower.
Note that Unicode code points may have various widths when printed on screen. This function acts like each code point is of width 1. This function should rather be used with text in Latin script.
See stri_trim_left
(among others) for reverse operation.
Also check out stri_wrap
for line wrapping.
stri_pad_left("stringi", 10, pad="#")
stri_pad_both("stringi", 8:12, pad="*")
# center on screen:
cat(stri_pad_both(c("the", "string", "processing", "package"),
getOption("width")*0.9), sep='\n')
Run the code above in your browser using DataLab