startsWith(x, prefix) endsWith(x, suffix)
| 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. |
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