Click here to Skip to main content
Click here to Skip to main content
Alternative Tip/Trick

Tagged as

Reverse of a string without using the Reverse function in C# and VB

, 25 Jul 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Another way,public static class ReverseStringExtension{ public static string Reverse(this string dataToRevese) { Func reverseFunc = (dataToFunc) => { StringBuilder reverseBuilder = new StringBuilder(); for (int index =...
Another way,
 
public static class ReverseStringExtension
{
    public static string Reverse(this string dataToRevese)
    {
        Func<string, string> reverseFunc = (dataToFunc) =>
        {
            StringBuilder reverseBuilder = new StringBuilder();
            for (int index = 0; index < dataToFunc.Length; )
                reverseBuilder.Append(dataToFunc[dataToFunc.Length - ++index]);
            return reverseBuilder.ToString();
        };
 
        return string.IsNullOrEmpty(dataToRevese) ? default(string) : reverseFunc(dataToRevese);
    }
}
 

Usage:
string stringRequireReverse = "Hello world, I am going to be reversed.";
stringRequireReverse = stringRequireReverse.Reverse();
Output:
.desrever eb ot gniog ma I ,dlrow olleH

License

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

Share

About the Author


Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150327.1 | Last Updated 25 Jul 2011
Article Copyright 2011 by Mohammad A Rahman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid