Click here to Skip to main content
15,879,184 members
Articles / Programming Languages / C#

Swap characters in a string

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
13 Nov 2011CPOL 8.2K   1  
Just for fun, using xor-swap, avoiding StringBuilder:string input = "AXBYCZ";char[] output = input.ToCharArray();for (int lo = 0, hi = 1; hi < output.Length; lo += 2, hi += 2){ output[lo] = (char)(output[lo] ^ output[hi]); output[hi] = (char)(output[lo] ^ output[hi]); ...

Views

Daily Counts

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions