Skip to contents

Pad a string and align within string

Usage

padstr(x, n, just = c("center", "left", "right"))

Arguments

x

string

n

number of character of the output string, if n < nchar(x) an error is thrown

just

character(1). Text alignment justification to use. Defaults to center. Must be center, right or left.

Value

x, padded to be a string of n characters

Examples


padstr("abc", 3)
#> [1] "abc"
padstr("abc", 4)
#> [1] "abc "
padstr("abc", 5)
#> [1] " abc "
padstr("abc", 5, "left")
#> [1] "abc  "
padstr("abc", 5, "right")
#> [1] "  abc"

if (interactive()) {
  padstr("abc", 1)
}