std-method
String::replace_range
Replace the selected byte interval with text, possibly changing length. Range endpoints must respect UTF-8 boundaries. Expected stdout (not executed): ID: ready Common mistake: Using inclusive ends as if they were exclusive.
Formal Syntax & Structure
rust syntaxrust
fn replace_range<R>(&mut self, range: R, replace_with: &str) where R: RangeBounds<usize>Working Example
Example Snippetrust
fn main() { let mut status = String::from("ID: old"); status.replace_range(4..7, "ready"); println!("{status}");}