To insert a character at a specific index in a string in Rust, you can use string concatenation and slicing.
In this example,
str
with a value of "Hello World"
.'!'
at index 5
.str
.fn main() {
let mut str = String::from("Hello World");
str.insert(5, '!');
println!("{}", str);
}
Hello! World
In this tutorial, we learned How to Insert Character at Specific Index in String in Rust language with well detailed examples.