Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created July 22, 2021 16:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/131e0da90c56c98bf1ad88597b1c90e2 to your computer and use it in GitHub Desktop.
Save cuongld2/131e0da90c56c98bf1ad88597b1c90e2 to your computer and use it in GitHub Desktop.
Comparison between .len() and .chars().count()
fn main() {
let s1=String::from("ラウトは難しいです!");
let len = calculate_length(&s1);
let chars = calculate_characters(&s1);
println!("The length of {:?} is {:?}.",s1,len);
println!("The number of chars of {:?} is {:?}.",s1,chars);
}
fn calculate_length(s: &String)-> usize{
s.len()
}
fn calculate_characters(s: &String)->usize{
s.chars().count()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment