Remove duplicates from string keeping the order according to last occurrences | 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 ; class GFG { static String removeDuplicates ( String str ) { int n = str . Length ; String res = " " ; for ( int i = 0 ; i < n ; i ++ ) { int j ; for ( j = i + 1 ; j < n ; j ++ ) if ( str [ i ] == str [ j ] ) break ; if ( j == n ) res = res + str [ i ] ; } return res ; } public static void Main ( String [ ] args ) { String str = " geeksforgeeks " ; Console . Write ( removeDuplicates ( str ) ) ; } }