Replace multiple keywords in a text

Hi everyone,

Is there a character function like sub () where I can replace multiple strings in a single line of code because I've tried sub(c(), c(), txt) But I got the following warning "Warning in sub() : argument 'pattern' has length > 1 and only the first element will be used"

Thanks,

stringr::str_replace_all() allows you to specify a named vector for replacing several patterns at once.

stringr::str_replace_all("abc", c('a' = 'x', 'b' = 'y', 'c' = 'z'))
#> [1] "xyz"

Created on 2022-06-26 by the reprex package (v2.0.1)

Note: Next time please provide a proper REPRoducible EXample (reprex) illustrating your issue.

It worked thanks a lot for your help :blush: :blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.