Vectorized over str
, [value
], from
and
(to
or length
).
to
and length
are mutually exclusive.
to
has priority over length
.
If from
is a two-column matrix, then the first column is used
as from
and the second one as to
. In such case arguments
to
and length
are ignored.
Of course, the indices are code point-based, and not byte-based.
Note that for some Unicode strings, the extracted substrings may not
be well-formed, especially if the input is not NFC-normalized
(see stri_trans_nfc
),
includes byte order marks, Bidirectional text marks, and so on.
Handle with care.
Indices 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.
Argument to
defines the last index of the substring, inclusive.
For negative indices 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.
In stri_sub
, out-of-bound indices are silently
corrected. If from
> to
, then an empty string is returned.
In stri_sub<-
, some configurations of indices may work as
string concatenation at the front, back, or middle.