Click here to Skip to main content
11,644,731 members (66,303 online)
Click here to Skip to main content

Tagged as

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

, 25 Jul 2011 CPOL 2.9K
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
Web01 | 2.8.150731.1 | Last Updated 25 Jul 2011
Article Copyright 2011 by Mohammad A Rahman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid