pad: Padding a string with justification, insertion

Description Usage Arguments Value Note Author(s) Examples

Description

Pad a string, insert substring.

Usage

1
2
3
  pad(str, space,just = c("right", "left", "center", "none"), with=" " )
  justify(str, space, just = c("right", "left", "center", "none"), with=" ")
  insstr(str, ins, point=nchar(str) )

Arguments

str, ins

String to be modified, to insert.

space

Integer, resulting length of padded string.

just

Mode of padding, of justification, one of "left","right","center", partial matching is allowed. If missing, "right" is taken, meaning for pad(just="r") right-ways extended (i.e. flush left), for justify(just="r") right-justified; "none" returns str unchanged.

with

String to pad with, will be repeated as often as necessary.

point

Integer, place of insertion. Appending is done for default value.

Value

pad, justify: The string padded with with.

insstr The string contained in ins inserted after character number point of str.

Note

pad(just="r") right-ways extended (i.e. flush left),

justify(just="r") right-justified,

just="none" returns str unchanged.

Author(s)

Christian W. Hoffmann <christian@echoffmann.ch>

Examples

1
2
3
4
5
6
pad("My string",25,"c","XoX")
 # [1] "XoXXoXXoMy stringXXoXXoXX"
pad("My string",25) # left aligned
(str <- paste00(LETTERS)) # "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
pad(str, 37, "right", " $ ")
insstr(str," $ ",7) # "ABCDEF $ GHIJKLMNOPQRSTUVWXYZ"

cwhmisc documentation built on May 1, 2019, 7:55 p.m.