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

String replace range

  • replace_range
fn main() {
    let mut text = String::from("The black cat climbed the green tree");
    println!("{text}");

    text.replace_range(10..13, "dog");
    println!("{text}");

    text.replace_range(10..13, "elephant");
    println!("{text}");
}
The black cat climbed the green tree
The black dog climbed the green tree
The black elephant climbed the green tree