text: Find uncommon characters of the two strings | Set 2 | C # implementation of the approach ; Function to print the uncommon characters in the given string in sorted order ; Converting character to ASCII code ; Bit operation ; Converting character to ASCII code ; Bit operation ; XOR operation leaves only uncommon characters in the ans variable ; Driver code
code: using System ; class GFG { static void printUncommon ( string str1 , string str2 ) { int a1 = 0 , a2 = 0 ; for ( int i = 0 ; i < str1 . Length ; i ++ ) { int ch = ( str1 [ i ] - ' a ' ) ; a1 = a1 | ( 1 << ch ) ; } for ( int i = 0 ; i < str2 . Length ; i ++ ) { int ch = ( str2 [ i ] - ' a ' ) ; a2 = a2 | ( 1 << ch ) ; } int ans = a1 ^ a2 ; int j = 0 ; while ( j < 26 ) { if ( ans % 2 == 1 ) { Console . Write ( ( char ) ( ' a ' + j ) ) ; } ans = ans / 2 ; j ++ ; } } public static void Main ( ) { string str1 = " geeksforgeeks " ; string str2 = " geeksquiz " ; printUncommon ( str1 , str2 ) ; } }