pub fn replace(string: &str, from: &str, to: &str) -> Result<String>Expand description
Replaces all matches of a pattern with another string.
replace creates a new String, and copies the data from this string slice into it.
While doing so, it attempts to find matches of a pattern. If it finds any, it
replaces them with the replacement string slice.
§Examples
Basic usage:
let s = "this is old";
assert_eq!("this is new", rune::alloc::str::replace(s, "old", "new")?);
assert_eq!("than an old", rune::alloc::str::replace(s, "is", "an")?);When the pattern doesn’t match, it returns this string slice as String:
let s = "this is old";
assert_eq!(s, rune::alloc::str::replace(s, "cookie monster", "little lamb")?);Single ascii-character replacements are optimized for performance:
assert_eq!("say", rune::alloc::str::replace("bay", "b", "s")?);