startsWith
Does String Start or End With Another String

### Description

Tests if a string starts or ends with a another string. The matching is literal: no regular expressions are allowed.

### Usage

    startsWith(x, prefix)
    endsWith(x, suffix)

### Arguments

x | a character vector to be matched into.
prefix | a character vector. startsWith returns TRUE when x starts with prefix.
suffix | a character vector. endsWith returns TRUE when x ends with prefix.

### Details

These functions are vectorized. The inputs x and prefix (or suffix) are replicated out to the maximum length of the two arguments. Then the matching is done on each element of x with each element of prefix (or suffix).
Value
returns a logical vector with length the maximum length of the two arguments.

- For startsWith, the value is TRUE if that element of x starts with the corresponding element of prefix.
- For endsWith, the value is TRUE if that element of x ends with the corresponding element of prefix.

See Also
grep, substring
Examples

    startsWith(c("thistle", "wheat", "maize"), "t")
    ## [1]  TRUE FALSE FALSE
    endsWith(c("thistle", "wheat", "maize"), "e")
    ## [1]  TRUE FALSE  TRUE
    endsWith(c("thistle", "wheat", "maize"), "ze")
    ## [1] FALSE FALSE  TRUE
    # The matching is literal, no regular expressions are processed:
    startsWith(c("one", "[a-z]", "[A-Z]"), prefix="[a-z]")
    ## [1] FALSE  TRUE FALSE
    #  Arguments are replicated out to maximum length:
    startsWith(c("A", "A", "B", "B"), prefix=c("A", "B"))
    ## [1]  TRUE FALSE FALSE  TRUE
    endsWith("tomato", suffix=c("a", "e", "i", "o", "u"))
    ## [1] FALSE FALSE FALSE  TRUE FALSE

Package base version 6.1.5-18
Package Index