Learn R Programming

DescTools (version 0.99.7)

StrPad: StrPad a String With Justification

Description

StrPad will fill a string x with some characters (str) to fit a given length.

Usage

StrPad(x, len, str = " ", adj = c("left", "right", "center"))

Arguments

x
string to be padded.
len
resulting length of padded string.
str
string to pad with. Will be repeated as often as necessary. Default is " ".
adj
adjustement of the old string, one of "left", "right", "center". If set to "left" the old string will be adjusted on the left and the new characters will be filled in on the right side.

Value

  • the string

Details

If a string x has more characters than len, it will be chopped on the length of len.

Examples

Run this code
StrPad("My string", 25, "XoX", "center")
 # [1] "XoXXoXXoMy stringXXoXXoXX"

Run the code above in your browser using DataLab