Given a string and a character, task is to make a function which count occurrence of the given character in the string.
Input : str = "geeksforgeeks" c = 'e' Output : 4 'e' appears four times in str. Input : str = "abccdefgaa" c = 'a' Output : 3 'a' appears three times in str.
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Count occurrence of a given character in a string using Stream API in Java
- Find the Nth occurrence of a character in the given String
- Minimize the length of string by removing occurrence of only one character
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Generate two output strings depending upon occurrence of character in input string.
- Generate two output strings depending upon occurrence of character in input string in Python
- Count occurrences of a character in a repeated string
- Count of number of given string in 2D character array
- Count of strings that can be formed from another string using each character at-most once
- Index of character depending on frequency count in string
- Program to find the kth character after decrypting a string
- Count substrings that starts with character X and ends with character Y
- Rearrange given string to maximize the occurrence of string t
- Find a string such that every character is lexicographically greater than its immediate next character
- Modify the string such that every character gets replaced with the next character in the keyboard