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 firstname.lastname@example.org. 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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Count occurrence of a given character in a string using Stream API in Java
- Python | Replacing Nth occurrence of multiple characters in a String with the given character
- Find the Nth occurrence of a character in the given String
- Remove the first and last occurrence of a given Character from a String
- 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
- Minimize the length of string by removing occurrence of only one character
- Rearrange given string to maximize the occurrence of string t
- Check if frequency of character in one string is a factor or multiple of frequency of same character in other string
- Longest suffix such that occurrence of each character is less than N after deleting atmost K characters
- Replace all occurrences of character X with character Y in given string
- Count maximum occurrence of subsequence in string such that indices in subsequence is in A.P.
- Count substrings that starts with character X and ends with character Y
- Find a string such that every character is lexicographically greater than its immediate next character
- Replace every character of string by character whose ASCII value is K times more than it
- Replace every character of a string by a different character
- Map every character of one string to another such that all occurrences are mapped to the same character
- Modify the string such that every character gets replaced with the next character in the keyboard
- Shortest distance to every other character from given character
- Find indices of all occurrence of one string in other