Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

pad

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"

cwhmisc

Miscellaneous Functions for Math, Plotting, Printing, Statistics, Strings, and Tools

v6.6
GPL (>= 2)
Authors
Christian W. Hoffmann
Initial release
2018-08-24, 10:40:10

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.