To iterate over characters in a string in Rust, you can use the chars method to get an iterator over Unicode characters.
In this example,
str
with a value of "Rust"
.chars
method on the string to get an iterator over Unicode characters.fn main() {
let str = String::from("Rust");
for c in str.chars() {
println!("{}", c);
}
}
R u s t
In this tutorial, we learned How to Iterate over Characters in String in Rust language with well detailed examples.