Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sing System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- class CountingWord
- {
- /*Write a program that counts how many times a given word occurs in given text. The first line in the input holds the word.
- * The second line of the input holds the text. The output should be a single integer number – the number of word occurrences.
- * Matching should be case-insensitive. Note that not all matching substrings are words and should be counted. A word is a sequence of letters
- * separated by punctuation or start / end of text.*/
- static void Main()
- {
- string word =Console.ReadLine();
- string text = Console.ReadLine();
- ExtractText(text, word);
- }
- static void ExtractText(string text, string word)
- {
- string[] splitText = text.ToUpper().Split('.','!');
- int counter = 0;
- for (int i = 0; i < splitText.Length; i++)
- {
- string[] splitWords = splitText[i].Split(' ','"',',','/','.','@','(',')');
- for (int j = 0; j < splitWords.Length; j++)
- {
- if (splitWords[j].ToUpper() == word.ToUpper())
- {
- counter++;
- }
- }
- }
- Console.WriteLine(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment