EVOLUTION-MANAGER
Edit File: startsWith.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: Does String Start or End With Another String?</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 startsWith {base}"><tr><td>startsWith {base}</td><td style="text-align: right;">R Documentation</td></tr></table> <h2>Does String Start or End With Another String?</h2> <h3>Description</h3> <p>Determines if entries of <code>x</code> start or end with string (entries of) <code>prefix</code> or <code>suffix</code> respectively, where strings are recycled to common lengths. </p> <p><code>startsWith()</code> is equivalent to but much faster than </p> <pre>substring(x, 1, nchar(prefix)) == prefix</pre> <p>or also </p> <pre>grepl("^<prefix>", x)</pre><p> where <code>prefix</code> is not to contain special regular expression characters. </p> <h3>Usage</h3> <pre> startsWith(x, prefix) endsWith(x, suffix) </pre> <h3>Arguments</h3> <table summary="R argblock"> <tr valign="top"><td><code>x</code></td> <td> <p>vector of <code><a href="character.html">character</a></code> string whose “starts” are considered.</p> </td></tr> <tr valign="top"><td><code>prefix, suffix</code></td> <td> <p><code><a href="character.html">character</a></code> vector (often of length one).</p> </td></tr> </table> <h3>Details</h3> <p>The code has an optimized branch for the most common usage in which <code>prefix</code> or <code>suffix</code> is of length one, and is further optimized in a UTF-8 or 8-byte locale if that is an ASCII string. </p> <h3>Value</h3> <p>A <code><a href="logical.html">logical</a></code> vector, of “common length” of <code>x</code> and <code>prefix</code> (or <code>suffix</code>), i.e., of the longer of the two lengths unless one of them is zero when the result is also of zero length. A shorter input is recycled to the output length. </p> <h3>See Also</h3> <p><code><a href="grep.html">grepl</a></code>, <code><a href="substr.html">substring</a></code>; the partial string matching functions <code><a href="charmatch.html">charmatch</a></code> and <code><a href="pmatch.html">pmatch</a></code> solve a different task. </p> <h3>Examples</h3> <pre> startsWith(search(), "package:") # typically at least two FALSE, nowadays often three x1 <- c("Foobar", "bla bla", "something", "another", "blu", "brown", "blau blüht der Enzian")# non-ASCII x2 <- cbind( startsWith(x1, "b"), startsWith(x1, "bl"), startsWith(x1, "bla"), endsWith(x1, "n"), endsWith(x1, "an")) rownames(x2) <- x1; colnames(x2) <- c("b", "b1", "bla", "n", "an") x2 </pre> <hr /><div style="text-align: center;">[Package <em>base</em> version 3.6.0 <a href="00Index.html">Index</a>]</div> </body></html>