Check if a string is a palindrome

后端 未结 30 1515
星月不相逢
星月不相逢 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条回答
  •  Happy的楠姐
    2020-11-28 09:37

    String extension method, easy to use:

        public static bool IsPalindrome(this string str)
        {
            str = new Regex("[^a-zA-Z]").Replace(str, "").ToLower();
            return !str.Where((t, i) => t != str[str.Length - i - 1]).Any();
        }
    

提交回复
热议问题