Print all distinct characters of a string in order ( 3 Methods ) | C # program to print distinct characters of a string . ; Print duplicates present in the passed string ; Create an array of size 256 and count of every character in it ; Count array with frequency of characters ; Print characters having count more than 0 ; Driver program
using System ; public class GFG { static int NO_OF_CHARS = 256 ; static void printDistinct ( String str ) { int [ ] count = new int [ NO_OF_CHARS ] ; int i ; for ( i = 0 ; i < str . Length ; i ++ ) if ( str [ i ] != ' ▁ ' ) count [ ( int ) str [ i ] ] ++ ; int n = i ; for ( i = 0 ; i < n ; i ++ ) if ( count [ ( int ) str [ i ] ] == 1 ) Console . Write ( str [ i ] ) ; } public static void Main ( ) { String str = " GeeksforGeeks " ; printDistinct ( str ) ; } }