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
.
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.
msmps
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
Wolfy7
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
ppavlovdev
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
tylp
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
bushuai
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
EphraimBsB
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
jualexandre
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
Beimodin
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
ejdraper
pub fn count_characters(s: &str) -> u32 { return s.chars().count() as u32;}
ndevc
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
toddlers
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string // let mut result:u32 = 0; // for c in s.chars(){ // result += 1 // } // result s.chars().fold(0,|acc, c| acc+1)}
anngoroshi
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count().try_into().unwrap()}
jeroen-rooijmans
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
area69base
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count().try_into().unwrap()}
MOmarMiraj
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
medzernik
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32 // Count the number of characters in the string}
jvoss
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
fennr
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count().try_into().unwrap()}
SCHTAMP
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
dawwestk
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
katopz
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
c-nielson
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
PavluninVladimir
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
moo-9523
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string return s.chars().count() as u32}
sainoe
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
tplive
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
kapaseker
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
longxinyi
pub fn count_characters(s: &str) -> u32 { let answer = s.chars().count(); answer as u32}
longxinyi
pub fn count_characters(s: &str) -> u32 { let answer = s.chars().count(); answer as u32}
tzmijewski
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
rado31
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
blietaer
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count().try_into().unwrap()}
tboot-0510
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
jonoswift7
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
djpandit007
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
sakkura
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
mm-yyyy
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
Dominicm99
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
ahmetoozcan
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
mshutov
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
bgraokmush
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32}
KhaleedhKhan
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
oelun-in
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
vikingNR
pub fn count_characters(s: &str) -> u32 { s.chars().count() as u32 // Count the number of characters in the string}
PavelPerna
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32 }
ryzen-xp
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let iter = s.chars(); let count = iter.count(); return count as u32 ;}
MaoX-Yu
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
matsuyama-k1
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string let iter = s.chars(); let count = iter.count(); return count as u32;}
i2z4
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}
rawar089
pub fn count_characters(s: &str) -> u32 { // Count the number of characters in the string s.chars().count() as u32}