Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Iterate over the characters of a string

  • chars
fn main() {
    let text = String::from("The black cat");
    println!("{text}");
    println!("{:?}", text.chars());

    for ch in text.chars() {
        println!("{ch}");
    }
}
The black cat
Chars(['T', 'h', 'e', ' ', 'b', 'l', 'a', 'c', 'k', ' ', 'c', 'a', 't'])
T
h
e
 
b
l
a
c
k
 
c
a
t