2
Reply

How to determine whether a String is a Palindrome or not in C#?

Kirtesh Shah

Kirtesh Shah

Dec 06
132
0
Reply

How to determine whether a String is a Palindrome or not in C#?

    Store the pallidrome var and check if it if they are equal

    static bool IsPalindrome(string str)
    {
    \/\/ Normalize the string
    str = str.ToLower();
    str = new string(Array.FindAll(str.ToCharArray(), char.IsLetterOrDigit));
    char[] charArray = str.ToCharArray();
    Array.Reverse(charArray);
    string reversedStr = new string(charArray);
    \/\/ Compare original and reversed string
    return str == reversedStr;
    }