Exemple #1
0
        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);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
 public void RunWordCounter()
 {
     Word     = Dissect(Word.ToLower());
     Sentence = Dissect(Sentence.ToLower());
     Count();
 }