Replace all occurrences of string AB with C without using extra space | C # program to replace all occurrences of " AB " with " C " ; Start traversing from second character ; If previous character is ' A ' and current character is 'B" ; Replace previous character with ' C ' and move all subsequent characters one position back ; Driver code
using System ; class GFG { static void translate ( char [ ] str ) { for ( int i = 1 ; i < str . Length ; i ++ ) { if ( str [ i - 1 ] == ' A ' && str [ i ] == ' B ' ) { str [ i - 1 ] = ' C ' ; int j ; for ( j = i ; j < str . Length - 1 ; j ++ ) str [ j ] = str [ j + 1 ] ; str [ j ] = ' ▁ ' ; } } return ; } public static void Main ( ) { String st = " helloABworldABGfG " ; char [ ] str = st . ToCharArray ( ) ; translate ( str ) ; Console . WriteLine ( " The ▁ modified ▁ string ▁ is ▁ : " ) ; Console . Write ( str ) ; } }