- len
Length of string
- With the len method we can get the length of a string in bytes.
examples/strings/length/src/main.rs
fn main() { let text = String::from("Hello World!"); println!("{text}"); let length = text.len(); println!("{length}"); let text = String::from("👻👽👾"); println!("{text}"); let length = text.len(); println!("{length}"); }
Hello World! 12 👻👽👾 12