Advertisement
Guest User

Problem 16.* Counting a Word in a Text

a guest
Aug 16th, 2014
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _16.Counting_a_Word_in_a_Text
  8. {
  9.     class CountingWordText
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Console.Write("Enter your word: ");
  14.             string word = Console.ReadLine().ToLower();
  15.             Console.WriteLine("Enter your text.");
  16.             string rowText = Console.ReadLine().ToLower();
  17.             int counter = 0;
  18.             string[] text = rowText.Split(' ', '(', ')', '.', '+', ',', '"', '/', '@', '!');
  19.             if (text.Contains(word))
  20.             {
  21.                 foreach (var item in text)
  22.                 {
  23.                     if (item == word)
  24.                     {
  25.                         counter++;
  26.                     }
  27.                 }
  28.                 Console.WriteLine("Times used --> {0}", counter);
  29.             }
  30.             else
  31.             {
  32.                 Console.WriteLine("Times used --> {0}", counter);
  33.             }
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement