re2r (version 0.2.0)

sub_string: Extract and replace substrings from a character vector.

Description

sub_string extracts substrings under code point-based index ranges provided. sub_string<- allows to substitute parts of a string with given strings.

Usage

sub_string(string, from = 1L, to = -1L)

sub_string(string, from = 1L, to = -1L) <- value

Arguments

string

input character vector.

from

an integer vector or a two-column matrix. from gives the position of the first character (defaults to first). Negative values count backwards from the last character.

to

an integer vector. to gives the position of the last (defaults to last character).

value

replacement string

Value

A character vector of substring from start to end (inclusive). Will be length of longest input argument.

See Also

The underlying implementation in stri_sub

Examples

Run this code
# NOT RUN {
sub_string("test", 1, 2)

x <- "ABC"

(sub_string(x, 1, 1) <- "A")
x
(sub_string(x, -2, -2) <- "GHIJ")
x
(sub_string(x, 2, -2) <- "")
x
# }

Run the code above in your browser using DataLab