stri_startswith {stringi} | R Documentation |
These functions check if a string starts or ends with a pattern occurrence.
stri_startswith(str, ..., fixed, coll, charclass) stri_endswith(str, ..., fixed, coll, charclass) stri_startswith_fixed(str, pattern, from = 1L, ..., opts_fixed = NULL) stri_endswith_fixed(str, pattern, to = -1L, ..., opts_fixed = NULL) stri_startswith_charclass(str, pattern, from = 1L) stri_endswith_charclass(str, pattern, to = -1L) stri_startswith_coll(str, pattern, from = 1L, ..., opts_collator = NULL) stri_endswith_coll(str, pattern, to = -1L, ..., opts_collator = NULL)
str |
character vector |
... |
supplementary arguments passed to the underlying functions,
including additional settings for |
pattern,fixed,coll,charclass |
character vector defining search patterns; for more details refer to stringi-search |
from |
integer vector |
to |
integer vector |
opts_collator,opts_fixed |
a named list used to tune up
a search engine's settings; see |
Vectorized over str
, pattern
,
and from
or to
.
If pattern
is empty, then the result is NA
and a warning is generated.
Argument start
controls the start position in str
at which the pattern
is matched.
On the other hand, to
gives the end position.
Indices given by from
or to
are 1-based,
i.e. an index equal to 1 denotes the first character
in a string, which gives a typical R look-and-feel.
For negative indices in from
or to
, counting starts
at the end of the string. E.g. index -1 denotes the last code point
in the string.
If you would like to test for a pattern match at any
position in str
, use stri_detect
.
stri_startswith
and stri_endswith
are convenience functions.
They call either stri_*_fixed
, stri_*_coll
,
or stri_*_charclass
, depending on the argument used.
Relying on those underlying functions directly will make your code run
slightly faster.
Note that testing for a pattern match at the start or end of a string
has not been implemented separately for regex patterns.
For that you may use the "^
" and "$
" metacharacters,
see stringi-search-regex.
All the functions return a logical vector.
Other search_detect: stri_detect
,
stri_detect_charclass
,
stri_detect_coll
,
stri_detect_fixed
,
stri_detect_regex
;
stringi-search
stri_startswith_charclass(" trim me! ", "\\p{WSpace}") stri_startswith_fixed(c("a1", "a2", "b3", "a4", "c5"), "a") stri_detect_regex(c("a1", "a2", "b3", "a4", "c5"), "^a") stri_startswith_fixed("ababa", "ba") stri_startswith_fixed("ababa", "ba", from=2) stri_startswith_coll(c("a1", "A2", "b3", "A4", "C5"), "a", strength=1) pat <- stri_paste("\u0635\u0644\u0649 \u0627\u0644\u0644\u0647 ", "\u0639\u0644\u064a\u0647 \u0648\u0633\u0644\u0645XYZ") stri_endswith_coll("\ufdfa\ufdfa\ufdfaXYZ", pat, strength=1)