padding {cwhmisc}R Documentation

Padding a string with justification, insertion

Description

Pad a string, insert substring.

Usage

  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

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"

[Package cwhmisc version 6.6 Index]