Forums » .NET » .NET »

c# - palindrome program


Posted Date: 11 May 2005      Posted By:: SRINIVASAN     Member Level: Silver    Member Rank: 0     Points: 2   Responses: 1



hi
if anyone can write a program to check for a palindrome?
eg:malayalam,madam
srini




Responses

#18176    Author: Brainstorming Guy      Member Level: Gold      Member Rank: 39     Date: 11/May/2005   Rating: 2 out of 52 out of 5     Points: 2

Hai,
You can use this piece of code

using System;

class MyString
{
public static void Main()
{
Console.WriteLine("Is 'rotator' PalinDrome:{0}",IsPalindrome("rotator"));
Console.WriteLine("Is 'visualc#' PalinDrome:{0}",IsPalindrome("visualc#"));
}

// Function to Test for Palindrome
public static bool IsPalindrome(String strParam)
{
int iLength,iHalfLen;
iLength=strParam.Length-1;
iHalfLen=iLength/2;
for(int iIndex=0;iIndex<=iHalfLen;iIndex++)
{
if(strParam.Substring(iIndex,1)!=strParam.Substring(iLength-iIndex,1))
{
return false;
}
}
return true;
}

}

Hope it helps you a bit.
If you have any queries, please feel free to post here.
Happy Coding!!!

Regards,
Brainstorming Guys

Regards,
Brainstorming Guy aka Venkatarajan A

BEEN THERE. DESTROYED THAT.


 
Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.



Previous : Is there any expert to solve this?
Return to Discussion Forum
Post New Message
Category: .NET

Subscribe to Subscribers
Awards & Gifts
Talk to Webmaster Tony John

Online Members

Touseef
More...
Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India