IsPalindrome
Checks to see if the given text is a valid palindrome or not.
Source
public static bool IsPalindrome(this string word)
{
int nLen, nHalfLen;
bool bValid = true;
nLen = word.Length - 1;
nHalfLen = nLen / 2;
for (int i = 0; i < nHalfLen; i++)
{
if (word.Substring(i, 1) != word.Substring(nLen - i, 1)) bValid = false;
}
return bValid;
}
Example
Console.WriteLine("Is Palindrome: {0}", "earljon".IsPalindrome()); // returns False
Console.WriteLine("Is Palindrome: {0}", "1234321".IsPalindrome()); // returns True