Tsallaka zuwa abun ciki
Justice Tech School

Chars and Bytes

Strings are UTF-8. chars() iterates characters and len counts bytes.

Example
fn main() {
    let s = "héllo";
    println!("{} {}", s.len(), s.chars().count());
    for c in "hé".chars() { print!("{} ", c); }
    println!();
}

Result

6 5
h é 

Exercise

Count characters.

s.chars().()

Quiz Test

What does len() count?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.