palindrome

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 2
Reputation: g_patron06 is an unknown quantity at this point 
Solved Threads: 0
g_patron06's Avatar
g_patron06 g_patron06 is offline Offline
Newbie Poster

palindrome

 
0
  #1
Mar 19th, 2007
i am curious about this palindrome....is there somebody give me some code so that i have a background knowledge to this topic,
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,273
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 378
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: palindrome

 
0
  #2
Mar 19th, 2007
What's more to say, it reads the same forwards as it does backwards. Separate the string to individual chars using the substring method.
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 2
Reputation: g_patron06 is an unknown quantity at this point 
Solved Threads: 0
g_patron06's Avatar
g_patron06 g_patron06 is offline Offline
Newbie Poster

Re: palindrome

 
0
  #3
Mar 19th, 2007
well...i try a lot of code...tnx! i know it helps a lot!!
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 71
Reputation: pygmalion is an unknown quantity at this point 
Solved Threads: 1
pygmalion's Avatar
pygmalion pygmalion is offline Offline
Junior Poster in Training

Re: palindrome

 
0
  #4
Mar 20th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 1
Reputation: gauravdudeja is an unknown quantity at this point 
Solved Threads: 0
gauravdudeja gauravdudeja is offline Offline
Newbie Poster

Re: palindrome

 
0
  #5
Jan 16th, 2009
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;
}

}
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 136
Reputation: cVz is an unknown quantity at this point 
Solved Threads: 7
cVz's Avatar
cVz cVz is offline Offline
Junior Poster

Re: palindrome

 
0
  #6
Jan 16th, 2009
You can try something like this

  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
Delphi & C# programmer deluxe...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



Tag cloud for C#
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC