text: Remove all occurrences of a character in a string | Recursive approach | C # program for the above approach ; Function to remove all occurrences of a character in the string ; Base Case ; Check the first character of the given string ; Pass the rest of the string to recursion Function call ; Add the first character of str and string from recursion ; Driver Code ; Given String ; Given character ; Function call
code: using System ; class GFG { static String removeCharRecursive ( String str , char X ) { if ( str . Length == 0 ) { return " " ; } if ( str [ 0 ] == X ) { return removeCharRecursive ( str . Substring ( 1 ) , X ) ; } return str [ 0 ] + removeCharRecursive ( str . Substring ( 1 ) , X ) ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; char X = ' e ' ; str = removeCharRecursive ( str , X ) ; Console . WriteLine ( str ) ; } }