Ian Beckett

RSS feed

    Recent comments

    Authors

    StringHelper class to reverse strings using C#

    I was surprised to find that C# does not have a built in method to reverse strings.  A quick search on Bing brought up the below code snippet from Sam Allen at dotnetperls.com.  The StringHelper class below contains a single static method named ReverseString.  Works like a charm!

    Input:  [1] framework
               [2] samuel
               [3] example string

    Output: [1] krowemarf
                [2] leumae
                [3] gnirts elpmaxe

    using System;

    static class StringHelper
    {
        /// <summary>
        /// Receives string and returns the string with its letters reversed.
        /// </summary>

        public static string ReverseString(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }
    }

    class Program
    {
        static void Main()
        {
            Console.WriteLine(StringHelper.ReverseString("framework"));
            Console.WriteLine(StringHelper.ReverseString("samuel"));
            Console.WriteLine(StringHelper.ReverseString("example string"));
        }
    }


    Posted by ibeckett on Tuesday, August 11, 2009 12:04 AM
    Permalink | Comments (0) | Post RSSRSS comment feed

    Build a Data-Driven Web Site in less than 14min

    "See how simple it is to create data-driven web sites using ASP.NET 2.0, Visual Web Developer 2005 Express Edition, and SQL Server 2005 Express Edition. Learn how to create a database, add its data, and display that data on a web page.

    Duration: 13 minutes, 41 seconds"

    watch it at http://www.asp.net/learn/videos/video-49.aspx 


    Categories: .NET | ASP.NET | C# | web stuff
    Posted by ibeckett on Tuesday, April 28, 2009 4:36 PM
    Permalink | Comments (0) | Post RSSRSS comment feed