sub_string: Extract and replace substrings from a character vector.

Description Usage Arguments Value See Also Examples

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

1
2
3
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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

Example output

[1] "te"
[1] "A"
[1] "ABC"
[1] "GHIJ"
[1] "AGHIJC"
[1] ""
[1] "AC"

re2r documentation built on May 2, 2019, 12:35 p.m.