To append a character to the end of a string in Rust, you can use the `push()` method of the `String` type.
In this example,
str1
with a value of "Hello World"
.push()
method to append the character '!'
to str1
.fn main() {
let mut str1 = String::from("Hello World");
str1.push('!');
println!("{}", str1);
}
Hello World!
In this example,
str2
with a value of "How are you"
.push()
method to append the character '?'
to str2
.fn main() {
let mut str2 = String::from("How are you");
str2.push('?');
println!("{}", str2);
}
How are you?
In this tutorial, we learned How to Append a Character to end of a String in Rust language with well detailed examples.