Skip to content

Instantly share code, notes, and snippets.

@eventhelix
Created May 14, 2022 17:04
Show Gist options
  • Save eventhelix/6b3fa04b7d5267f706cfa2f09508758b to your computer and use it in GitHub Desktop.
Save eventhelix/6b3fa04b7d5267f706cfa2f09508758b to your computer and use it in GitHub Desktop.
Count characters in a string
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