EVOLUTION-MANAGER
Edit File: trimws.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>R: Remove Leading/Trailing Whitespace</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <link rel="stylesheet" type="text/css" href="R.css" /> </head><body> <table width="100%" summary="page for trimws {base}"><tr><td>trimws {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Remove Leading/Trailing Whitespace</h2> <h3>Description</h3> <p>Remove leading and/or trailing whitespace from character strings. </p> <h3>Usage</h3> <pre> trimws(x, which = c("both", "left", "right"), whitespace = "[ \t\r\n]") </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>a character vector</p> </td></tr> <tr valign="top"><td><code>which</code></td> <td> <p>a character string specifying whether to remove both leading and trailing whitespace (default), or only leading (<code>"left"</code>) or trailing (<code>"right"</code>). Can be abbreviated.</p> </td></tr> <tr valign="top"><td><code>whitespace</code></td> <td> <p>a string specifying a regular expression to match (one character of) “white space”, see Details for alternatives to the default.</p> </td></tr> </table> <h3>Details</h3> <p>Internally, <code><a href="grep.html">sub</a>(re, "", *, perl = TRUE)</code>, i.e., PCRE library regular expressions are used. For portability, the default ‘whitespace’ is the character class <code>[ \t\r\n]</code> (space, horizontal tab, carriage return, newline). Alternatively, <code>[\h\v]</code> is a good (PCRE) generalization to match all Unicode horizontal and vertical white space characters, see also <a href="https://www.pcre.org">https://www.pcre.org</a>. </p> <h3>Examples</h3> <pre> x <- " Some text. " x trimws(x) trimws(x, "l") trimws(x, "r") ## Unicode --> need "stronger" 'whitespace' to match all : tt <- "text with unicode 'non breakable space'." xu <- paste(" \t\v", tt, "\u00a0 \n\r") (tu <- trimws(xu, whitespace = "[\\h\\v]")) stopifnot(identical(tu, tt)) </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>