Check if a string is a palindrome

后端 未结 30 1571
星月不相逢
星月不相逢 2020-11-28 08:59

I have a string as input and have to break the string in two substrings. If the left substring equals the right substring then do some logic.

How can I do this?

30条回答
  •  甜味超标
    2020-11-28 09:18

    protected bool CheckIfPalindrome(string text)
    {
        if (text != null)
        {
            string strToUpper = Text.ToUpper();
            char[] toReverse = strToUpper.ToCharArray();
            Array.Reverse(toReverse );
            String strReverse = new String(toReverse);
            if (strToUpper == toReverse)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    

    Use this the sipmlest way.

提交回复
热议问题