std-method
String::insert
Insert a scalar at a valid byte boundary. Later bytes may need to move to make room. Expected stdout (not executed): A-ب Common mistake: Using a scalar index instead of a byte offset.
Formal Syntax & Structure
rust syntaxrust
fn insert(&mut self, idx: usize, ch: char)Working Example
Example Snippetrust
fn main() { let mut text = String::from("Aب"); text.insert(1, '-'); println!("{text}");}