Miyerkules, Enero 11, 2012

C# ConApp 6: count the word in the message

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


namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.Write(" enter a message ");
            string message = Console.ReadLine();


            Console.Write(" enter a word ");
            string word = Console.ReadLine();


            int wordcount = 0;


            int index = 0;


            while (message.IndexOf(word, index) >= 0)
            {
                wordcount++;
                index = message.IndexOf(word, index) + word.Length;


            }


            Console.WriteLine("number of words : " + wordcount);








            Console.ReadLine();
        }
    }
}

Walang komento:

Mag-post ng isang Komento