C# programming
What is the code to check whether a string is a palindrome?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Sep 20, 2007, 3:47 PM
The code in Mahesh's link deals with a numeric palindrome. The following code deals with a string palindrome:
using System;
class StringPalindrome
{
static void Main()
{
string[] sa = new string[]{"rotor", "caravan", "level", "palindrome"};
foreach (string s in sa)
{
char[] ca = (char[])s.ToCharArray().Clone();
Array.Reverse(ca);
string rev = new string(ca);
string temp = (s == rev) ? "is" : "is not";
Console.WriteLine("\"{0}\" {1} a palindrome", s, temp);
}
Console.ReadLine();
}
}
Mahesh ChandPosted Sep 20, 2007, 8:04 AM
Here are some samples including palindrome.
http://www.c-sharpcorner.com/UploadFile/nrsurapaneni/SortSeachNRS11242005061300AM/SortSeachNRS.aspx
Jan MontanoPosted Sep 20, 2007, 6:39 AM
The code for the palindrome is not that hard. Have you tried to actually coding it yourself? How far have you been with it?
Cheers,
Jan