Toggle case of a string using Bitwise Operators | C # program to get toggle case of a string ; tOGGLE cASE = swaps CAPS to lower case and lower case to CAPS ; Bitwise EXOR with 32 ; Driver program
using System ; class GFG { static string toggleCase ( char [ ] a ) { for ( int i = 0 ; i < a . Length ; i ++ ) { a [ i ] ^= ( char ) 32 ; } return new string ( a ) ; } public static void Main ( ) { string str = " CheRrY " ; Console . Write ( " Toggle ▁ case : ▁ " ) ; str = toggleCase ( str . ToCharArray ( ) ) ; Console . WriteLine ( str ) ; Console . Write ( " Original ▁ string : ▁ " ) ; str = toggleCase ( str . ToCharArray ( ) ) ; Console . Write ( str ) ; } }