Reverse a String in C#
If you need a function to reverse a string in C#, here it is!
private string ReverseString(string InputStr) { char[] Chars = InputStr.ToCharArray(); int Length = InputStr.Length-1;for (int x=0;x<Length;x++,Length--) { Chars[x] ^= Chars[Length]; Chars[Length] ^= Chars[x]; Chars[x] ^= Chars[Length]; }return new string(Chars); }


umm….. Chars.Reverse()
http://www.livejournal.com/users/his_insignifica/10122.html
Detailed discussions; do not miss the link in the end to the unmanaged reversal discussion.
Short and too the point. Nice post. Do you know how to write a string palendrome program in C# ?
Ishita: There’s a solution here – http://www.csharphelp.com/archives/archive12.html
You could also try something like this (not tested).
public bool isPalindrome (string str)
{
int length = str.Length;
if (length < = 1) return true;
if (str [0] == str [length-1])
{
length = length – 2;
return isPalindrome (str+1);
}
else
return false;
}
public static string ReverseString(string input)
{
char[] forward = input.ToCharArray();
StringBuilder reverse = new StringBuilder(input.Length);
for (int i = input.Length – 1; i >= 0; i—)
reverse.Append(forward[i]);
return reverse.ToString();
}
public static string Reverse(string str)
{
char[] chars = str.ToCharArray();
Array.Reverse(chars);
return new string(chars);
}