Created
July 22, 2021 16:03
-
-
Save cuongld2/131e0da90c56c98bf1ad88597b1c90e2 to your computer and use it in GitHub Desktop.
Comparison between .len() and .chars().count()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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