Learn R Programming

misty (version 0.6.7)

chr.trim: Trim Whitespace from String

Description

This function removes whitespace from start and/or end of a string

Usage

chr.trim(x, side = c("both", "left", "right"), check = TRUE)

Value

Returns a character vector with whitespaces removed from the vector specified in x.

Arguments

x

a character vector.

side

a character string indicating the side on which to remove whitespace, i.e., "both" (default), "left" or "right".

check

logical: if TRUE (default), argument specification is checked.

Author

Takuya Yanagida takuya.yanagida@univie.ac.at

References

Wickham, H. (2019). stringr: Simple, consistent wrappers for common string operations. R package version 1.4.0.

See Also

chr.grep, chr.grepl, chr.gsub, chr.omit

Examples

Run this code
x <- "  string  "

# Example 1: Remove whitespace at both sides
chr.trim(x)

# Example 2: Remove whitespace at the left side
chr.trim(x, side = "left")

# Example 3: Remove whitespace at the right side
chr.trim(x, side = "right")

Run the code above in your browser using DataLab