add trim() for Q3 of type-conversions

add `.map(|x| x.trim()) ` for Q3 of type-conversions
增加`"3, 4"`答案中有空格的情况
This commit is contained in:
Gengen Wang
2023-11-02 14:25:44 +08:00
committed by GitHub
parent f6e96bc9f9
commit 91724a5136

View File

@ -61,6 +61,7 @@ impl FromStr for Point {
fn from_str(s: &str) -> Result<Self, Self::Err> { fn from_str(s: &str) -> Result<Self, Self::Err> {
let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' ) let coords: Vec<&str> = s.trim_matches(|p| p == '(' || p == ')' )
.split(',') .split(',')
.map(|x| x.trim())
.collect(); .collect();
let x_fromstr = coords[0].parse::<i32>()?; let x_fromstr = coords[0].parse::<i32>()?;
@ -165,4 +166,4 @@ fn main() {
} }
``` ```
> 你可以在[这里](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md)找到答案(在 solutions 路径下) > 你可以在[这里](https://github.com/sunface/rust-by-practice/blob/master/solutions/type-conversions/others.md)找到答案(在 solutions 路径下)