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?
3 Respostas
+ 1
How to know which one contain white space, beginning input or end of input
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.
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