To replace a substring in a string in Rust, you can use the `replace()` method of the `String` type or regular expressions.
In this example,
str
with a value of "Hello World"
.replace()
method of the String
type to replace the substring "World"
with "Universe"
.str
.fn main() {
let mut str = String::from("Hello World");
str = str.replace("World", "Universe");
println!("{}", str);
}
Hello Universe
In this tutorial, we learned How to Replace a Substring in String in Rust language with well detailed examples.