Objects in this mirror are closer to Microsoft Technologies. DNM objective is to help users on Microsoft technologies by providing Articles, snippets, Interview Questions.

24 July 2012

NET Program to check whether the given string is palindrome string or not with out using any builtin funcitons


In this snippet we will write a program to check whether the given string is palindrome string or not.

What is palindrome String?
Palindrome string is a string that remains the same when its chars are reversed
Example: string 'wowow' is a palindrome string.
string 'dotnetmirror'- it not a palindrome string.

Snippet:
class PalindromeString
    {
        static bool CheckPalindrome(string CheckString)
        {
            if (CheckString == null || CheckString.Length == 0)
            {
                return false;
            }
            int strMaxIndex = CheckString.Length - 1;
            for (int i = 0; i < CheckString.Length / 2; i++)
            {
                if (CheckString[i] != CheckString[strMaxIndex - i])
                {
                    return false;
                }
            }
            return true;
        }
        public static void Main()
        {
            Console.WriteLine("********** Palindrome string Check Example ********");
            Console.WriteLine();
            Console.Write("Enter string to you want to check: ");
            string str = Console.ReadLine();
            if (CheckPalindrome(str))
            {
                Console.WriteLine("{0} is a Palindrome String", str);
            }
            else
            {
                Console.WriteLine("{0} is not a Palindrome String", str);
            }
           
            Console.ReadLine();
        }
}

Output:
 Example : Input =wowow (palindrome string)
Fig1 : Palindrome string "wowow"








Example : Input =dotnetmirror (not a palindrome string)
Fig2 : Not a Palindrome string "dotnetmirror"

 Example : Input =maddam(palindrome string)
Fig3 : Palindrome string "maddam"
 




0 Comments:

Post a Comment