ankur ankur - 3 months ago 17
C# Question

Check if a string is a palindrome

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

How can I do this?

Sample:

public bool getStatus(string myString)
{

}


Example:
myString
= "ankYkna", so if we break it into two substring it would be:
left-part = "ank".
right-part = "ank" (after reversal).

Answer
public static bool getStatus(string myString)
    {
        string first = myString.Substring(0, myString.Length / 2);
        char[] arr = myString.ToCharArray();
        Array.Reverse(arr);
        string temp = new string(arr);
        string second = temp.Substring(0, temp.Length / 2);
        return first.Equals(second);
    }