53

I have tried using the to_string method on the char but this returns a &str when I need a String.

1
  • Thanks for your reply. Maybe i got horribly confused somewhere. Chronium's answer is perfect however. Commented Jun 17, 2016 at 20:40

2 Answers 2

84

Using String::push method is the easiest method:

let mut a_string = String::from("Hello World"); a_string.push('!'); 
Sign up to request clarification or add additional context in comments.

Comments

10

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); } 

https://doc.rust-lang.org/std/macro.format.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.