Remove duplicates from a given string | C # program to remove duplicate character from character array and print in sorted order ; Used as index in the modified string ; Traverse through all characters ; Check if str [ i ] is present before it ; If not present , then add it to result . ; Driver code
using System ; using System . Collections . Generic ; class GFG { static String removeDuplicate ( char [ ] str , int n ) { int index = 0 ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = 0 ; j < i ; j ++ ) { if ( str [ i ] == str [ j ] ) { break ; } } if ( j == i ) { str [ index ++ ] = str [ i ] ; } } char [ ] ans = new char [ index ] ; Array . Copy ( str , ans , index ) ; return String . Join ( " " , ans ) ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; Console . WriteLine ( removeDuplicate ( str , n ) ) ; } }