static void Main() { Console.WriteLine("Give me a word to search."); string inputtedWord = Console.ReadLine(); Console.WriteLine("Give me a sentence to search for the word."); string inputtedSentence = Console.ReadLine(); RepeatCounter newWord = new RepeatCounter(inputtedWord); newWord.SetSentence(inputtedSentence); Console.WriteLine(newWord.GetWord() + " occured " + newWord.SearchWord() + " times."); }
public static void InitApp() { Console.Clear(); Console.Write("Please enter a sentence:"); string userString = Console.ReadLine(); Console.Write("Enter the word you'd like to count:"); string userWord = Console.ReadLine(); RepeatCounter newRepeat = new RepeatCounter(userString, userWord); newRepeat.CountWord(); newRepeat.Results(newRepeat); }
public static void Main() { Console.WriteLine( @" Hello, and welcome to my program! Today we're going to scan a given sentence to see if (and how many times) a particular sequence of letters or symbols in it occurs. First, give me a series of letters, numbers, or symbols to scan."); string templateString = Console.ReadLine(); Console.WriteLine( @" Next: give me a series of letters numbers or symbols to scan for."); string scanString = Console.ReadLine(); RepeatCounter scanner = new RepeatCounter(templateString, scanString); Console.WriteLine(scanner.CountOccurrences()); }
public void Results(RepeatCounter newRepeat) { Console.Clear(); if (newRepeat.WordCount == 1) { Console.WriteLine("The word " + newRepeat.UserWord + " is in your sentence " + newRepeat.WordCount + " time."); } else if (newRepeat.WordCount == 0) { Console.WriteLine("Sorry, we couldn't find any instances of " + newRepeat.UserWord + " in your sentence."); } else { Console.WriteLine("The word " + newRepeat.UserWord + " is in your sentence " + newRepeat.WordCount + " times."); } Console.WriteLine("========================================="); Console.WriteLine("Please enter one of the numbers below:"); Console.WriteLine("1. Check another word in my sentence."); Console.WriteLine("2. Start over with a new sentence."); Console.WriteLine("3. Exit Application."); string userChoice = Console.ReadLine(); if (userChoice == "1") { CheckAnother(newRepeat); } else if (userChoice == "2") { RepeatCounter.InitApp(); } else { Environment.Exit(0); } }
public static int PerformWordCount(RepeatCounter newRepeatCounter) { string sentence = newRepeatCounter.GetSentence(); string chosenWord = newRepeatCounter.GetChosenWord(); int wordTotal = 0; char[] delimiterChars = { ' ', ',', '.', ':', '!', '\t' }; string[] words = sentence.Split(delimiterChars); for (int x = 0; x < words.Length; x++) { if (words[x] == chosenWord) { wordTotal++; } else { } } newRepeatCounter.SetWordCount(wordTotal); return(wordTotal); }
public void CountOccurrences__ReturnsCountOfInstancesIncludingFilterConditions_Two() { RepeatCounter counter = new RepeatCounter("cat in a cat bag", "cat"); Assert.AreEqual("Your search string occurs: 2 times in the host string.", counter.CountOccurrences()); }
public void ValidInputFullWord_True() { bool output = RepeatCounter.ValidInput("brain"); Assert.AreEqual(true, output); }
public void EmptyInput_False() { bool output = RepeatCounter.ValidInput(" "); Assert.AreEqual(false, output); }
public void NumberInWord_False() { bool output = RepeatCounter.ValidInput("br4in"); Assert.AreEqual(false, output); }
public void SpecialCharacters_False() { bool output = RepeatCounter.ValidInput("br@in"); Assert.AreEqual(false, output); }
public int Count(bool caseSensitive) { return(RepeatCounter.Count(_word, _wordList, caseSensitive)); }