How to check whether a sentence is palindrome in C#

1 Answer

0 votes
using System;
using System.Linq;
 
public class Palindrome_CSharp
{
    public static bool IsSentencePalindrome(string str) {
        // Change the string into lowercase and remove all non-alphanumeric characters
        str = new string(str.ToLower().Where(c => char.IsLetterOrDigit(c)).ToArray());
 
        return str == new string(str.Reverse().ToArray());
    }
 
    public static void Main(string[] args)
    {
        Console.WriteLine(IsSentencePalindrome("Top step's pup's pet spot.") ? "yes" : "no");
    }
}
 
 
 
/*
run:
     
yes
    
*/

 



answered Jun 30, 2024 by avibootz
edited Jul 1, 2024 by avibootz

Related questions

1 answer 119 views
1 answer 119 views
1 answer 123 views
1 answer 121 views
1 answer 125 views
1 answer 116 views
1 answer 107 views
...