public string ModifyFirstWordToAnalyze()
 {
     return(string.Join("",
                        FirstWord
                        .Replace(" ", "")
                        .ToLower()
                        .ToArray()
                        .OrderBy(letter => letter)
                        ));
 }
示例#2
0
        public bool IsAnagram()
        {
            char[] firstwordCharArray  = FirstWord.ToLower().ToCharArray();
            char[] secondwordCharArray = SecondWord.ToLower().ToCharArray();

            Array.Sort(firstwordCharArray);
            Array.Sort(secondwordCharArray);

            return(new string(firstwordCharArray) == new string(secondwordCharArray));
        }
示例#3
0
 /// <summary>
 /// Check if words are anagram
 /// </summary>
 /// <returns></returns>
 public bool AreAnagram()
 {
     if (IsValid)
     {
         // Sort first word
         // Sort second word
         // Apply sequence equal
         // return result
         return(FirstWord.ToArray().OrderBy(A => A).SequenceEqual(SecondWord.ToArray().OrderBy(B => B)));
     }
     else
     {
         return(false);
     }
 }
示例#4
0
        static void Main(string[] args)
        {
            string FirstWord, SecondWord;
            bool   result;

            Console.WriteLine("Escriba la primera palabra");
            FirstWord = Console.ReadLine();
            Console.WriteLine("Escriba la segunda palabra");
            SecondWord = Console.ReadLine();

            FirstWord.ToLower();
            SecondWord.ToLower();

            char[] FirstWordArr  = FirstWord.ToCharArray();
            char[] SecondWordArr = SecondWord.ToCharArray();

            if (FirstWordArr.Length != FirstWordArr.Length)
            {
                result = false;
            }
            else
            {
                Array.Sort(FirstWordArr);
                Array.Sort(SecondWordArr);

                if (FirstWordArr == SecondWordArr)
                {
                    result = true;
                }
                else
                {
                    result = false;
                }
            }

            if (result)
            {
                Console.WriteLine("Son anagrama");
            }
            else
            {
                Console.WriteLine("No son anagramas");
            }
        }
示例#5
0
        public bool IsAnagram()
        {
            if (FirstWord.Length != SecondWord.Length)
            {
                return(false);
            }
            else
            {
                Char[] firstStringArray  = FirstWord.Replace(" ", "").ToLower().ToCharArray();
                Char[] secondStringArray = SecondWord.Replace(" ", "").ToLower().ToCharArray();

                var result = firstStringArray.Except(secondStringArray);
                if (result.Count() == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }