![]() |
VOOZH | about |
Given a string and a character, remove all the occurrences of the character in the string.
Examples:
Input : s = "geeksforgeeks"
c = 'e'
Output : s = "gksforgks"
Input : s = "geeksforgeeks"
c = 'g'
Output : s = "eeksforeeks"
Input : s = "geeksforgeeks"
c = 'k'
Output : s = "geesforgees"
Table of Content
This approach uses the built-in Replace() function. It directly replaces all occurrences of the given character with an empty string (""), effectively removing them from the original string.
bbc
This approach iterates through the string and retains only the characters that are not equal to the given character by shifting them toward the beginning of the string. After processing all characters, the string is resized to remove the leftover characters at the end.
eeksforeeks