Click here to Skip to main content
12,074,485 members (61,731 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

3.2K views
Posted

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


You may also be interested in...

Comments and Discussions

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