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?
Here is an absolutely simple way to do this,
This is a nice way as u don't have to cast ints and doubles. U can just pass them to the method in their string representation by using the ToString() method.
public static bool IsPalindrome(string word)
{
string spare = word;
string reversal = null;
while (word.Length > 0)
{
reversal = string.Concat(reversal, word.LastOrDefault());
word = word.Remove(word.Length - 1);
}
return spare.Equals(reversal);
}
So from your main method, For even and odd length strings u just pass the whole string into the method.