Thursday, 2 April 2015

Console Program

Write a C# Programme ?
I have a string "nbaguarirot". you have to Check if it contains all the characters of nagarro word in sequence.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace nagarro
{
    public class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            p.checkString("nbaguarirot");
            Console.ReadLine();
        }

        public void checkString(string name)
        {
            StringBuilder builder = new StringBuilder();
            char[] myarray = { 'n', 'a', 'g', 'a', 'r', 'r', 'o' };

            int i = 0;
            foreach (char item in myarray)
            {
                for (int a= i; a <= name.Length; a++)
                {
                    char val = Convert.ToChar(name.Substring(i, 1));
                    if (item == val)
                    {
                        builder.Append(val);
                        i++; break;
                    }
                    else
                    {
                        i++;
                        continue;
                    }
                }
            }
            StringBuilder b = new StringBuilder();
            b.Append("nagarro");

            if (b.Equals(builder))
            {
                Console.Write("true");
            }
            else
            {
                Console.Write("false");
            }
        }
    }
}

0 comments:

Post a Comment

Topics

ADO .Net (2) Ajax (1) Angular Js (17) Angular2 (24) ASP .Net (14) Azure (1) Breeze.js (1) C# (49) CloudComputing (1) CMS (1) CSS (2) Design_Pattern (3) DI (3) Dotnet (21) Entity Framework (3) ExpressJS (4) Html (3) IIS (1) Javascript (6) Jquery (9) Lamda (3) Linq (11) Mongodb (1) MVC (48) NodeJS (7) RDLC (1) Report (1) Sql Server (29) SSIS (3) SSRS (2) UI (1) WCF (12) Web Api (10) Web Service (1) XMl (1)