str.split_whitespace()
.map(|w| w[..1].to_uppercase() +&w[1..].to_lowercase())
.collect()
w[0]
and w[..1]
are exactly the same, but I know that using w[0]
caused an error. I want to know why the error occurred.
What i know about both of them:
w[0]
returns a single character, and w[..1]
returns a string slice containing the first character.