i am curious about this palindrome....is there somebody give me some code so that i have a background knowledge to this topic,

Recommended Answers

All 5 Replies

Member Avatar for iamthwee

What's more to say, it reads the same forwards as it does backwards. Separate the string to individual chars using the substring method.

well...i try a lot of code...tnx! i know it helps a lot!!

well, the following code should do it:

bool CheckPalindrome (string CheckString)
{
     if (CheckString == null || CheckString.Length == 0) 
     {
        return false;
     }
     for (int i = 0; i < CheckString.Length / 2; i++)
     {
         if (CheckString[i] != CheckString[CheckString.Length - 1 - i])
         {
            return false;
         }
     }
     return true;
}

hope this helped
pygmalion

This code may help you.

public bool PolinDrome()
{
string str = "atita";
int len = str.Length;
string strReverse = "";
for (int i = len - 1; i >= 0; i--)
{


strReverse = strReverse + str;
}
if (strReverse == str)
{
return true;
}
else
{
return false;
}


}

You can try something like this

public static bool IsPalindrome(string strValue)
        {
            int intLen, intStrPartLen;
            intLen = strValue.Length - 1;

            //Cut the length of the string into 2 halfs
            intStrPartLen = intLen / 2;

            for (int intIndex = 0; intIndex <= intStrPartLen; intIndex++)
            {
                //intIndex is the index of the char in the front of the string
                //Check from behind and front for match
                if (strValue[intIndex] != strValue[intLen])
                {
                    return false;
                }
                //decrease the lenght of the original string to
                //test the next Char from behind
                intLen--;
            }
            return true;
        }

You have fun now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.