Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Create empty string and grow it using push and push_str

  • String::new
  • push
  • push_str
fn main() {
    let mut text = String::new();
    println!("{text:?}");

    text.push_str("Hello");
    println!("{text:?}");

    text.push(' ');
    println!("{text:?}");

    text.push_str("World");
    println!("{text:?}");

    text.push('!');
    println!("{text:?}");
}
""
"Hello"
"Hello "
"Hello World"
"Hello World!"