I have written a function to prompt for input and return the result. In this version the returned string includes a trailing newline from the user. I would like to return th
A more generic solution than the accepted one, that works with any kind of line ending:
fn main() { let mut s = "hello\r\n".to_string(); let len_withoutcrlf = s.trim_right().len(); s.truncate(len_withoutcrlf); assert_eq!("hello", &s); }