Exemple #1
0
        public string RepeatedWordChecker(string input)
        {
            input = input.ToLower();

            string[] inputArray = input.Split(" ");

            HashTable table = new HashTable();

            foreach (string word in inputArray)
            {
                if (table.Contains(word))
                {
                    return(word);
                }
                table.Add(word);
            }

            return(null);
        }
Exemple #2
0
        public static string RepeatedWord(string word)
        {
            string[] words = word.Split(' ');

            HashTable newTable = new HashTable();

            for (int i = 0; i < words.Length; i++)
            {
                string repeated = Regex.Replace(words[i].ToLower(), @"(\p{P})]", "");

                if (newTable.Contains(repeated))
                {
                    return(newTable.Get(repeated).Value);
                }

                newTable.Add(repeated, repeated);
            }
            return("All unique words");
        }
Exemple #3
0
        /// <summary>
        /// finds the first word that repeats in a string
        /// </summary>
        /// <param name="sentence"> the inputted string</param>
        /// <returns>  the repeated word in the string</returns>
        public static string FindRepeatedWord(string sentence)
        {
            char[]   charArray = new char[] { ',', '/', '!', ' ', '?' };
            string[] stringArr = sentence.Split(charArray);

            int             v      = 0;
            string          repeat = "Not Found";
            HashTable <int> Table  = new HashTable <int>(sentence.Length * 2);

            foreach (string item in stringArr)
            {
                if (Table.Contains(item.ToUpper()))
                {
                    return(repeat = item.ToLower());
                }
                else
                {
                    Table.Add(item.ToUpper(), v);
                    v++;
                }
            }

            return(repeat);
        }
        /// <summary>
        /// This takes in a string and returns the first repeated word.
        /// </summary>
        /// <param name="input">The input string</param>
        /// <returns>The first repeated word</returns>
        public static string RepeatedWord(string input)
        {
            if (input == null)
            {
                return("");
            }
            string[]  array       = input.Split(" ");
            HashTable uniqueWords = new HashTable();

            foreach (string word in array)
            {
                string replacePeriod         = word.Replace(".", "");
                string replaceCommaAndPeriod = replacePeriod.Replace(",", "");
                try
                {
                    uniqueWords.Add(replaceCommaAndPeriod.ToLower(), 1);
                }
                catch (Exception)
                {
                    return(replaceCommaAndPeriod);
                }
            }
            return("");
        }