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

Remove leading and trailing whitespace

  • trim

  • trim_end

  • trim_start

  • Read more about trim and the related functions.

fn main() {
    let text = String::from("  Some text  ");
    println!("original:   '{}'", text);
    println!("trim_end:   '{}'", text.trim_end());
    println!("trim_start: '{}'", text.trim_start());
    println!("trim:       '{}'", text.trim());
}
original:   '  Some text  '
trim_end:   '  Some text'
trim_start: 'Some text  '
trim:       'Some text'