Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- class CountingAWordInAtext
- {
- static void Main()
- {
- Console.Write("Enter the word which will be counted in the text : ");
- string searchWord = Console.ReadLine();
- Console.WriteLine("Enter the text.");
- string text = Console.ReadLine();
- string lowerWord = searchWord.ToLower();
- string[] textArray = text.Split(new char[] { '.', '?', '!', ' ', ';', ':', ',', '"', '(', ')', '/', '@' },
- StringSplitOptions.RemoveEmptyEntries);
- for (int i = 0; i < textArray.Length; i++)
- {
- textArray[i] = textArray[i].ToLower();
- }
- int counter = 0;
- for (int i = 0; i < textArray.Length; i++)
- {
- if (textArray[i].Contains(lowerWord) && (textArray[i].Length == lowerWord.Length))
- {
- counter++;
- }
- else
- {
- continue;
- }
- }
- Console.WriteLine(counter);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement