0

Which one should i use in rust trim() or trim_end

let user_guessed = user_guessed.trim() // Or let user_guessed = user_guessed.trim_end() Which one is better?

15th Feb 2022, 5:24 AM
EsaKurniawan
3 Answers
+ 1
How to know which one contain white space, beginning input or end of input
15th Feb 2022, 5:57 AM
EsaKurniawan
0
The methods' name kinda explain what they do. trim() strips whitespace from beginning & end of string. trim_end() only strips whitespace from end of string. It's not about which one is better, it's more about necessity. Whether input may (or not) contain whitespace in the beginning and/or end of string.
15th Feb 2022, 5:49 AM
Ipang
0
Don't know Rust, but maybe you can check by passing each character in the beginning of the string to is_whitespace() https://doc.rust-lang.org/std/primitive.char.html#method.is_whitespace https://doc.rust-lang.org/src/core/char/methods.rs.html#809
15th Feb 2022, 6:25 AM
Ipang