Vectorized over str
, [value
], from
and
(to
or length
). Parameters
to
and length
are mutually exclusive.
Indexes are 1-based, i.e., the start of a string is at index 1.
For negative indexes in from
or to
,
counting starts at the end of the string.
For instance, index -1 denotes the last code point in the string.
Non-positive length
gives an empty string.
Argument from
gives the start of a substring to extract.
Argument to
defines the last index of a substring, inclusive.
Alternatively, its length
may be provided.
If from
is a two-column matrix, then these two columns are
used as from
and to
, respectively,
unless the second column is named length
.
In such a case anything passed
explicitly as to
or length
is ignored.
Such types of index matrices are generated by stri_locate_first
and stri_locate_last
. If extraction based on
stri_locate_all
is needed, see
stri_sub_all
.
In stri_sub
, out-of-bound indexes are silently
corrected. If from
> to
, then an empty string is returned.
By default, negative length
results in the corresponding output being
NA
, see ignore_negative_length
, though.
In stri_sub<-
, some configurations of indexes may work as
substring 'injection' at the front, back, or in middle.
Negative length
does not alter the corresponding input string.
If both to
and length
are provided,
length
has priority over to
.
Note that for some Unicode strings, the extracted substrings might not
be well-formed, especially if input strings are not normalized
(see stri_trans_nfc
),
include byte order marks, Bidirectional text marks, and so on.
Handle with care.