replace_string.Rd
Function that replaces a specified pattern found within a string (or vector of strings) with a user-specified pattern.
replace_string(s, to_replace, replace_with = "")
A character vector.
A character vector, the patterns to match and replace within each string.
An optional character vector,
either of length one or of matching length to
to_replace
, the patterns to substitute.
A character string.
# Example string
x <- c( 'AA', 'AB', 'AC', 'DD' )
# Remove the letter 'A'
replace_string( x, 'A' )
#> [1] "" "B" "C" "DD"
# Replace the letter 'A' with '1'
replace_string( x, 'A', '1' )
#> [1] "11" "1B" "1C" "DD"
# Replace multiple letters
replace_string( x, c( 'B', 'C' ), c( '1', '2' ) )
#> [1] "AA" "A1" "A2" "DD"