Skip to content

Instantly share code, notes, and snippets.

@maretekent
Created September 4, 2018 21:00
Show Gist options
  • Save maretekent/cd9ead9667a88b4d25c97ebfa86953a1 to your computer and use it in GitHub Desktop.
Save maretekent/cd9ead9667a88b4d25c97ebfa86953a1 to your computer and use it in GitHub Desktop.
rust read int like 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