Code Snippets

  

C# Source Code


Welcome to Dream.In.Code
Become a C# Expert!

Join 137,222 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,125 people online right now. Registration is fast and FREE... Join Now!





Reverse a string using XOR

In this snippet we will be using XOR to reverse the string provided

Submitted By: PsychoCoder
Actions:
Rating:
Views: 511

Language: C#

Last Modified: August 5, 2008

Snippet


  1. public string ReverseString(string str)
  2. {
  3.     char[] array = str.ToCharArray();
  4.     int len = str.Length - 1;
  5.  
  6.     for (int i = 0; i < len; i++, len--)
  7.     {
  8.         array[i] ^= array[len];
  9.         array[len] ^= array[i];
  10.         array[i] ^= array[len];
  11.     }
  12.  
  13.     return new string(array);
  14. }

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month