I have tried using the to_string method on the char but this returns a &str when I need a String.
- Thanks for your reply. Maybe i got horribly confused somewhere. Chronium's answer is perfect however.unskilledidiot– unskilledidiot2016-06-17 20:40:07 +00:00Commented Jun 17, 2016 at 20:40
Add a comment |
2 Answers
Using String::push method is the easiest method:
let mut a_string = String::from("Hello World"); a_string.push('!'); Comments
You can also use format!:
fn main() { let s = String::from("March"); // example 1 let s1 = format!("{}!", s); // example 2 let s2 = format!("{}{}", s, '!'); // print println!("{} {}", s1, s2); }