Skip to content

Instantly share code, notes, and snippets.

@rpivo
Last active July 11, 2021 13:00
Show Gist options
  • Save rpivo/3d809007a79ff6c0702b2cfdc42c02ab to your computer and use it in GitHub Desktop.
Save rpivo/3d809007a79ff6c0702b2cfdc42c02ab to your computer and use it in GitHub Desktop.
Iterating Through Each Letter of a String in Rust

Iterating Through Each Letter of a String in Rust

The String method chars() returns an iterator containing each character of the original string.

fn main() {
    let s = "hello";
    let c = s.chars();
    for x in c { println!("{}", x); }
}
// h
// e
// l
// l
// o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment