Length of string
-
len
-
With the
len
method we can get the length of a string in bytes.
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