Created
May 14, 2022 17:04
-
-
Save eventhelix/6b3fa04b7d5267f706cfa2f09508758b to your computer and use it in GitHub Desktop.
Count characters in a string
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
pub fn count_char(find: char, search_str: &str) -> usize { | |
let mut count = 0; | |
for next in search_str.chars() { | |
if find == next { | |
count += 1; | |
} | |
} | |
count | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment