stringi (version 0.2-3)

stri_pad_both: Pad (Center/Left/Right Align) a String

Description

Adds multiple 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.

Usage

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 = " ")

Arguments

str
character vector
min_length
integer vector giving minimal output string lengths
side
[stri_pad only] single character string; sides on which padding character is added (left, right, or both)
pad
character vector giving padding code points

Value

  • Returns a character vector.

Details

Vectorized over 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.

Examples

Run this code
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