Ejemplo n.º 1
0
        public static void Main(string[] args)
        {
            //Instantiate Objects for later use.
            TaskOneAndTwo taskOneAndTwoObject = new TaskOneAndTwo();
            TaskThree     taskThreeObject     = new TaskThree();

            //Instantiate Arrays for later use
            string[] arr  = { "dog", "cat", "large" };
            string[] arr2 = { "Meow", "Woof" };

            int resLetterOccurence = taskOneAndTwoObject.LetterOccurence("I have some cheese", 'e');

            bool resIsPalindrome  = taskOneAndTwoObject.IsPalindrome("I have some cheese");
            bool resIsPalindrome1 = taskOneAndTwoObject.IsPalindrome("God saved Eva’s dog");

            string resCensoredWord  = taskThreeObject.CensoredWord(arr, "I have a cat named Meow and a dog name Woof. I love the dog a lot. He is larger than a small horse.");
            string resCensoredWord2 = taskThreeObject.CensoredWord2(arr2, "I have a cat named Meow and a dog name Woof.I love the dog a lot.He is larger than a small horse.");
            string resCensoredWord3 = taskThreeObject.CensoredWord3("Anna went to vote in the election to fulfil her civic duty", taskOneAndTwoObject);

            Console.WriteLine("Result Letter Occurence: \n" + resLetterOccurence);
            Console.WriteLine("\nResult is Palindrome: \n" + resIsPalindrome);
            Console.WriteLine("\nResult is Palindrome: \n" + resIsPalindrome1);
            Console.WriteLine("\nResult is Censord Word: \n" + resCensoredWord);
            Console.WriteLine("\nResult Censord Word2: \n" + resCensoredWord2);
            Console.WriteLine("\nResult Censord Word3: \n" + resCensoredWord3);
        }
Ejemplo n.º 2
0
        public String CensoredWord3(String sentence, TaskOneAndTwo TaskOneAndTwoObject)
        {
            int i = 0;

            String[] words = sentence.Replace(".", " ").Split(" ");

            //Add words to censored list, replace characters at required index
            //

            foreach (string currWord in words)
            {
                if (TaskOneAndTwoObject.IsPalindrome(currWord))
                {
                    words[i] = currWord.Remove(1, currWord.Length - 2).Insert(1, "$").Insert(2, "$");
                }

                i += 1;
            }


            return(string.Join(" ", words));
        }