Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

str_replace_all with multiple replacements #516

Closed
Close-your-eyes opened this issue Jul 2, 2023 · 1 comment
Closed

str_replace_all with multiple replacements #516

Close-your-eyes opened this issue Jul 2, 2023 · 1 comment

Comments

@Close-your-eyes
Copy link

Close-your-eyes commented Jul 2, 2023

The result of stringr::str_replace_all("abcd", pattern = c("a" = "d", "d" = "x")) is "xbcx". That means, patterns are replaced one after the other: 'a' first becomes 'd' and in second round 'd' becomes 'x'. So, 'a' becomes 'x'.

What do I have to do to get "dbcx" as result?

I expect it is not possible with stringr::str_replace_all. But, is there another function to do it and if not, is the behaviour I desire too weird to be covered by stringr::str_replace_all?

@hadley
Copy link
Member

hadley commented Aug 4, 2023

I don't know of any easy way to do that, sorry.

@hadley hadley closed this as completed Aug 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants