Created
September 4, 2018 21:00
-
-
Save maretekent/cd9ead9667a88b4d25c97ebfa86953a1 to your computer and use it in GitHub Desktop.
rust read int like characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let a = "29"; | |
for c in a.chars() { | |
println!("{}", c as u32 - 48); | |
} | |
let mut sum = 0; | |
let x = 14183; | |
let x = x.to_string(); | |
for y in x.chars() { | |
// converting `y` to string and then to integer | |
let z = (y.to_string()).parse::<i32>().unwrap(); | |
// incrementing `sum` by `z` | |
sum += z; | |
} | |
println!("{}", sum); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment