944,051 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 18837
  • C# RSS
Mar 19th, 2007
0

palindrome

Expand Post »
i am curious about this palindrome....is there somebody give me some code so that i have a background knowledge to this topic,
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
g_patron06 is offline Offline
2 posts
since Mar 2007
Mar 19th, 2007
0

Re: palindrome

What's more to say, it reads the same forwards as it does backwards. Separate the string to individual chars using the substring method.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Mar 19th, 2007
0

Re: palindrome

well...i try a lot of code...tnx! i know it helps a lot!!
Reputation Points: 10
Solved Threads: 0
Newbie Poster
g_patron06 is offline Offline
2 posts
since Mar 2007
Mar 20th, 2007
0

Re: palindrome

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
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
pygmalion is offline Offline
71 posts
since Dec 2006
Jan 16th, 2009
1

Re: palindrome

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[i];
}
if (strReverse == str)
{
return true;
}
else
{
return false;
}

}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gauravdudeja is offline Offline
1 posts
since Jan 2009
Jan 16th, 2009
0

Re: palindrome

You can try something like this

C# Syntax (Toggle Plain Text)
  1. public static bool IsPalindrome(string strValue)
  2. {
  3. int intLen, intStrPartLen;
  4. intLen = strValue.Length - 1;
  5.  
  6. //Cut the length of the string into 2 halfs
  7. intStrPartLen = intLen / 2;
  8.  
  9. for (int intIndex = 0; intIndex <= intStrPartLen; intIndex++)
  10. {
  11. //intIndex is the index of the char in the front of the string
  12. //Check from behind and front for match
  13. if (strValue[intIndex] != strValue[intLen])
  14. {
  15. return false;
  16. }
  17. //decrease the lenght of the original string to
  18. //test the next Char from behind
  19. intLen--;
  20. }
  21. return true;
  22. }

You have fun now
cVz
Reputation Points: 29
Solved Threads: 7
Junior Poster
cVz is offline Offline
139 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Simple Question??
Next Thread in C# Forum Timeline: Combo Box





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC