This package is complementary to stringr package. It includes three functions: string_insert
, string_cut
and string_replace
. string_insert
inserts a string to another string at a given position. string_cut
cuts a substring between two given positions from a string. string_replace
replaces a substring between two given positions in a string with another string.
devtools::install_github("mynamedaike/string")
Import string library
library(string)
string_insert inserts a string to another string at a given position
a <- "apple pear "
b <- "banana "
string_insert(a, b, as.integer(0))
#> [1] "banana apple pear "
string_insert(a, b, as.integer(6))
#> [1] "apple banana pear "
string_insert(a, b, as.integer(11))
#> [1] "apple pear banana "
string_cut cuts a substring between two given positions from a string
a <- "apple banana pear "
string_cut(a, as.integer(1), as.integer(6))
#> [1] "banana pear "
string_cut(a, as.integer(7), as.integer(13))
#> [1] "apple pear "
string_cut(a, as.integer(14), as.integer(18))
#> [1] "apple banana "
string_replace replaces a substring between two given positions in a string with another string
a <- "apple banana pear "
b <- "orange"
string_replace(a, b, as.integer(1), as.integer(5))
#> [1] "orange banana pear "
string_replace(a, b, as.integer(7), as.integer(12))
#> [1] "apple orange pear "
string_replace(a, b, as.integer(14), as.integer(17))
#> [1] "apple banana orange "