xxxxxxxxxx
fn main() {
let my_string = String::from("Hello, world!");
// Using chars method to iterate over each character in the string
for ch in my_string.chars() {
println!("{}", ch);
}
}
xxxxxxxxxx
let hello = "नमस्ते";
// Characters
for c in hello.chars() {
println!("{}", c);
}
// Bytes
for b in hello.bytes() {
println!("{}", b);
}
xxxxxxxxxx
for c in my_str.chars() {
// do something with `c`
}
for (i, c) in my_str.chars().enumerate() {
// do something with character `c` and index `i`
}