Learn R Programming

berryFunctions (version 1.11.0)

removeSpace: Remove white spaces from strings

Description

Remove leading and/or trailing white space from character strings

Usage

removeSpace(x, begin = TRUE, end = TRUE, all = FALSE, ...)

Arguments

x
Character string, can be a vector
begin
Logical. Remove leading spaces at the beginning of the character string? DEFAULT: TRUE
end
Logical. Remove trailing spaces at the end? DEFAULT: TRUE
all
Logical. Remove all spaces anywhere in the string? DEFAULT: FALSE
...
Further arguments passed to sub or gsub, like ignore.case, perl, fixed, useBytes.

Value

Character string (vector)

See Also

sub

Examples

Run this code

s <- c("space at end     ", "  white at begin", "  both ", " special ^  ")
removeSpace(s)

# To add space, use:
x <- c("ab","abcde")
format(x)
format(x, justify="centre")
format(x, width=9)

Run the code above in your browser using DataLab