cswork / libraryOpen practice workspace

Interview questions · Discord

Count a Character in a String

Count case-sensitive occurrences of a character in a string, including empty input and repeated matches.

Implement number_of_character(string, char).

  • string is the input string.
  • char is the single character whose occurrences you must count.

Return an integer giving the number of times char appears in string. Comparison is case-sensitive: uppercase and lowercase forms are different characters. Count every matching occurrence, including repeated adjacent occurrences.

Return zero if the input string contains no occurrence of char, including when the input string is empty. The returned count is a scalar, so its value is the complete output.

Community answers

Nothing here yet.

Join in on CSWork →