Character replacement after removing duplicates from a string | C # program for character replacement after String minimization ; Function to minimize String ; duplicate characters are removed ; checks if character has previously occurred or not if not then add it to the minimized String ' mstr ' ; return mstr ; minimized String ; Utility function to print the minimized , replaced String ; Creating final String by replacing character ; index calculation ; final String ; Driver Code
using System ; class GFG { static String minimize ( string str ) { string mstr = " ▁ " ; int l , i ; int [ ] flagchar = new int [ 26 ] ; char ch ; l = str . Length ; for ( i = 0 ; i < str . Length ; i ++ ) { ch = str [ i ] ; if ( flagchar [ ch - 97 ] == 0 ) { mstr = mstr + ch ; flagchar [ ch - 97 ] = 1 ; } } } static void replaceMinimizeUtil ( string str ) { string minimizedStr , finalStr = " " ; int i , index , l ; char ch ; l = str . Length ; for ( i = 0 ; i < minimizedStr . Length ; i ++ ) { ch = minimizedStr [ i ] ; index = ( ch * ch ) % l ; finalStr = finalStr + str [ index ] ; } Console . Write ( " Final ▁ String : ▁ " + finalStr ) ; } public static void Main ( ) { string str = " geeks " ; replaceMinimizeUtil ( str ) ; } }