DotNet Mirror
  DNM facebook   DNM Google+   DNM Twitter   

C#.NET string palindrome program without using string functions

By Ashok Nalam on 15 Mar 2015 | Category: C# | Tagged: string palindrome .NET 
In this snippet we will write a program to check whether the given string is palindrome string or not with out using any built-in string function.
  Discuss Add Comment   |  
Add rating Rate this resource   

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

using System;
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:

Example1 : Input =wowow (palindrome string)
palindromestring_wowow

Example2 : Input =dotnetmirror (not a palindrome string)
palindrome string: dotnetmirror

Example3 : Input =maddam(palindrome string)
  Discuss Add Comment    
Add rating Rate this resource   
About the Contributor
Member Since : 10 Dec 2012
Member Points (Level) : 9526  (Professional)
Location : INDIA
Home Page : http://dotnetmirror.com
About : I am admin of this site.
Rate this resource
 
Add your Comment
Name Email WebSite
Captcha Refresh


Comments (0)
No comments found, click here to add comment.
 
cheap jordans|wholesale air max|wholesale jordans|wholesale jewelry|wholesale jerseys