Friday, December 29, 2006

strReverse in C#

Just came across this small piece of code while I was looking out to reverse a string in C# and soon discovered there was nothing like strReverse (in VB) in C#.

So obviously needed to look for an alternate. Got quite a few of them but this one looked quite nifty and sleek. Take a look
private string StringReverse(string ToReverse)


Array arr = ToReverse.ToCharArray();

Array.Reverse( arr );// reverse the string

char[] c = (char[])arr;

byte[] b = System.Text.Encoding.Default.GetBytes(c);

return System.Text.Encoding.Default.GetString(b);


-- Ashutosh

No comments:

Post a Comment