Check if a string is a palindrome

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

    static void Main(string[] args)
    {
        string str, rev="";
    
        Console.Write("Enter string");
    
        str = Console.ReadLine();
    
        for (int i = str.Length - 1; i >= 0; i--)
        {
            rev = rev + str[i];
        }
    
        if (rev == str)
            Console.Write("Entered string is pallindrome");
        else
            Console.Write("Entered string is not pallindrome");
    
        Console.ReadKey();
    }
    

提交回复
热议问题