Learn R Programming

sjmisc (version 1.5)

trim: Trim leading and trailing whitespaces from strings

Description

Trims leading and trailing whitespaces from strings or character vectors.

Usage

trim(x)

Arguments

x
Character vector or string. Function is vectorized, i.e. vector may have a length greater than 1. See 'Examples'.

Value

  • Trimmed x, i.e. with leading and trailing spaces removed.

Examples

Run this code
trim("white space at end ")
trim("white space at start and end ")
trim(c("string1 ", "string2", "string 3   "))

Run the code above in your browser using DataLab