Avatar ·

How to idiomatically replace certain characters in a string in Rust?

Hi everyone! I just started learning Rust and encountered a problem when working with strings. I need to replace all occurrences of certain characters in a string with other characters. For example, I have the string "hello-world_foo" and I want to replace the hyphen and underscore with spaces to get "hello world foo". In Python, I would simply do: `s.replace('-', ' ').replace('_', ' ')`. But in Rust, I can't find such a simple way. I tried using the `replace` method, but it only works with one character or substring at a time: ```rust let s = "hello-world_foo"; let result = s.replace("-", " ").replace("_", " "); println!("{}", result); // "hello world foo" ``` This works, but it seems not very efficient and not idiomatic for Rust. I've heard that there are regular expressions, b