Remove duplicates from a given string | C # program to remove duplicate character from character array and print in sorted order ; Create a set using String characters excluding ' \0' ; Print content of the set ; Driver code
using System ; using System . Collections . Generic ; public class GFG { static char [ ] removeDuplicate ( char [ ] str , int n ) { HashSet < char > s = new HashSet < char > ( n - 1 ) ; foreach ( char x in str ) s . Add ( x ) ; char [ ] st = new char [ s . Count ] ; int i = 0 ; foreach ( char x in s ) st [ i ++ ] = x ; return st ; } public static void Main ( String [ ] args ) { char [ ] str = " geeksforgeeks " . ToCharArray ( ) ; int n = str . Length ; Console . Write ( removeDuplicate ( str , n ) ) ; } }