Substitute all occurences using gsub



examples/strings/replace_substrings.R
text <- "One cat two cats and another single cat"
print(text)
print(gsub('cat', 'dog', text))
print(text)

[1] "One cat two cats and another single cat"
[1] "One dog two dogs and another single dog"
[1] "One cat two cats and another single cat"