I'm doing a school exercise where the user inputs a string and the program must check if it's a palindrome. My only problem currently is that I can't get the loop to ignore whitespaces included in the input string.
Console.Write("Insert string: ");
string input = Console.ReadLine();
char[] charArray = new char[input.Length];
for (int i = 0; i < input.Length; i++)
{
if (Char.IsWhiteSpace(input, i))
{
continue;
}
else
{
charArray[i] += input[i];
}
}
string original = new string(charArray);
I've seemingly tried everything I know, but the whitespaces just get added to the array no matter what I try. Is there a simple solution for this?