Advertisement
gardax

CountingWordInText

Apr 9th, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _16_CountingWordInText
  5. {
  6.     class CountingWordInText
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string wordToSearch = Console.ReadLine();
  11.             string text = Console.ReadLine();
  12.             foreach (var symbol in text)
  13.             {
  14.                 if(!Char.IsLetter(symbol))
  15.                 {
  16.                     text=text.Replace(symbol, ' ');
  17.                 }
  18.             }
  19.             string[] list = text.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
  20.             string wordToSearchToLower = wordToSearch.ToLower();
  21.             int count = list.Count(w => w.ToLower() == wordToSearchToLower);
  22.             Console.WriteLine(count);
  23.         }
  24.     }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement