Tuesday, July 16, 2013

Palindrome Checking in C#



Here is a short code to do this:

       private string CheckPalinDrome(string text)
        {
            //Converting into Upper case and remove blank spaces in between
            text = textBox2.Text.ToUpper().Replace(" ", string.Empty);
            string revText = ReverseString(text);
            if (revText == text)
            {
               return("palindrome");
            }
            else
            {
                return ("Not palindrome");
            }
        }

        private string ReverseString(string s)
        {
            char[] arr = s.ToCharArray();
            Array.Reverse(arr);
            return new string(arr);
        }

No comments:

Post a Comment