Monday, June 4, 2012

How to check string is palindrome or not in .NET

public bool isPalindrome(String str)
{
    if (String.IsNullOrEmpty(str))
        return false;
 
    int length = str.Length;
 
    str = str.ToLower();
 
    for (int i = 0; i < (length / 2); i++)
    {
        if (str[i] != str[length - 1 - i])
            return false;
    }
 
    return true;
}

No comments:

Post a Comment