public static int SearchWords() { int count = 0; string wordCheck = Word.ToLower(); string sentenceCheck; char[] charsToTrim = { ',', '.', '\'', '\"', ' ', '!', '?', ';', ':' }; string[] sentenceArr = Sentence.Split(" "); for (int i = 0; i < sentenceArr.Length; i++) { sentenceCheck = sentenceArr[i].ToLower().Trim(charsToTrim); if (wordCheck == sentenceCheck) { count++; } // Check for Apostrophe else if (wordCheck.Length > 1 && wordCheck + "\'s" == sentenceCheck || wordCheck + "\'m" == sentenceCheck || wordCheck + "\'re" == sentenceCheck || wordCheck + "\'t" == sentenceCheck || wordCheck + "\ve" == sentenceCheck || wordCheck + "\'ll" == sentenceCheck) { count++; } // Check for Plural else if (wordCheck.Length > 1 && wordCheck + "s" == sentenceCheck || wordCheck + "es" == sentenceCheck) { count++; } } return(count); }
public int CaseInsensitiveMatches() { int matches = 0; string[] words = Str.Split(" "); foreach (string word in words) { if (RemovePunctuation(word.ToLower()) == Word.ToLower() || word.ToLower() == Word.ToLower()) { matches++; } } return(matches); }
public int WordCount() { int count = 0; string toLowerCaseWord = Word.ToLower(); string toLowerCaseSentence = Sentence.ToLower(); string[] sentenceWords = toLowerCaseSentence.Split(' ', '.', ',', '?', '!', '/', ';', ':', '"'); foreach (string invidualWords in sentenceWords) { if (toLowerCaseWord == invidualWords) { count++; } } return(count); }
public void RunWordCounter() { Word = Dissect(Word.ToLower()); Sentence = Dissect(Sentence.ToLower()); Count(); }