std-method
String::split_off
Keep the prefix in the original String and obtain an owned suffix. The split point must be a valid byte boundary. Expected stdout (not executed): user: 42 Common mistake: Expecting two borrowed slices instead of owned strings.
Formal Syntax & Structure
rust syntaxrust
fn split_off(&mut self, at: usize) -> StringWorking Example
Example Snippetrust
fn main() { let mut text = String::from("user:42"); let suffix = text.split_off(5); println!("{text} {suffix}");}