Check if a string is a palindrome

后端 未结 30 1488
星月不相逢
星月不相逢 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:27

    class Program
    {
        static void Main(string[] args)
        {
    
            string s, revs = "";
            Console.WriteLine(" Enter string");
            s = Console.ReadLine();
            for (int i = s.Length - 1; i >= 0; i--) //String Reverse
            {
                Console.WriteLine(i);
                revs += s[i].ToString();
            }
            if (revs == s) // Checking whether string is palindrome or not
            {
                Console.WriteLine("String is Palindrome");
            }
            else
            {
                Console.WriteLine("String is not Palindrome");
            }
            Console.ReadKey();
        }
    }
    

提交回复
热议问题