You are given a string s
. Your task is to count the number of characters in the string and return the total amount of characters in the string with the type u32
.
let s = "hello";
let result = character_counting_string(s);
assert_eq!(result, 5);
chars()
method to get an iterator over the characters in the string.count()
method to count the number of elements in the iterator.The
count()
method returns ausize
which is the number of elements in the iterator. In the challenge you are asked to return au32
, you can use theas
keyword to convert theusize
to au32
. For example,let count_u32 = count as u32;
Don't use
len()
: This length is in bytes, not [char
]s or graphemes. In other words, it might not be what a human considers the length of the string.
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32 }
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().collect::<Vec<char>>().len() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let mut count = 0; for _ in s.chars(){ count += 1; } return count;}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.to_string().chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let num: u32 = s.chars().count() as u32; num}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let chars = s.chars(); let count_u32 = chars.count() as u32; count_u32}
pub fn count_characters(s: &str) -> u32 { let chars = s.chars(); let count_u32 = chars.count() as u32; count_u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let count = s.chars().count(); return count as u32;}
pub fn count_characters(s: &str) -> u32 { let count = s.chars().count(); return count as u32;}
pub fn count_characters(s: &str) -> u32 { return s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let a = s.chars(); return a.count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32;}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { let nb_characters: u32 = s.chars().count() as u32; return nb_characters;}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32;}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let count = s.chars().count(); let count_u32 = count as u32; return count_u32;}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.to_string().chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let count = s.chars().count() as u32; count}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32;}
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the strig s.chars().count() as u32 }