Scrolling Text Pattern

using System;

using System.Net;

using System.Text;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            string str = "HAPPY NEW YEAR 2010";

            int displaySize = 19;

            for (int i = 0; i < (str.Length + displaySize); i++)

            {

                if (i < Math.Min(displaySize, str.Length))

                {

                    Console.WriteLine(Display(str, i, displaySize, false));

                }

                else

                {

                    Console.WriteLine(Display(str, i – displaySize + 1, displaySize, true));

                }

            }

        }

        public static string Display(string str, int startIndex, int length, bool append)

        {

            string disp = "";

            if (append)

            {

                while (startIndex < 0)

                {

                    disp = " " + disp;

                    startIndex++;

                }

                if (startIndex >= 0)

                {

                    disp = disp + str.Substring(startIndex, Math.Min(str.Length – startIndex, length));

                    for (int i = disp.Length; i < length; i++)

                    {

                        disp = disp + " ";

                    }

                }

            }

            else

            {

                disp = str.Substring(0, Math.Min(startIndex + 1, str.Length));

                for (int i = disp.Length; i < length; i++)

                {

                    disp = " " + disp;

                }

            }

            return disp;

        }

    }

}

                  H
                 HA
                HAP
               HAPP
              HAPPY
             HAPPY
            HAPPY N
           HAPPY NE
          HAPPY NEW
         HAPPY NEW
        HAPPY NEW Y
       HAPPY NEW YE
      HAPPY NEW YEA
     HAPPY NEW YEAR
    HAPPY NEW YEAR
   HAPPY NEW YEAR 2
  HAPPY NEW YEAR 20
 HAPPY NEW YEAR 201
HAPPY NEW YEAR 2010
APPY NEW YEAR 2010
PPY NEW YEAR 2010
PY NEW YEAR 2010
Y NEW YEAR 2010
 NEW YEAR 2010
NEW YEAR 2010
EW YEAR 2010
W YEAR 2010
 YEAR 2010
YEAR 2010
EAR 2010
AR 2010
R 2010
 2010
2010
010
10
0

 

Press any key to continue . . .

Advertisements
This entry was posted in Information Technology. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s