This is my first foray into OOP, so I'd appreciate any kind of advice!
Here is the problem description:
On the first line of the input, you will receive a number specifying how many lines of input to read. After that, the input consists of some number of lines of text that you will read and determine whether or not it is a palindrome.
The only important factor in validating palindromes is whether or not a sequence of letters is the same backwards and forwards. All other types of characters (spaces, punctuation, newlines, etc.) should be ignored, and whether a character is lower-case or upper-case is irrelevant.
Here is my code:
class Program
{
static void Main(string[] args)
{
Console.WriteLine("How many lines will you be entering? ");
int numberOfLines = Int32.Parse(Console.ReadLine());
string mergedLine = MergeMultipleLinesIntoOneLine(numberOfLines);
bool isPalindrome = IsPalindrome(mergedLine);
Console.WriteLine(isPalindrome ? "Palindrome" : "Not a palindrome");
}
public static string MergeMultipleLinesIntoOneLine(int numberOfLines)
{
int line = 1;
var stringResult = new StringBuilder();
do
{
Console.WriteLine("Please enter phrase #{0}: ", line);
stringResult.Append(Console.ReadLine() + " ");
line++;
} while (line <= numberOfLines);
return stringResult.ToString();
}
public static bool IsPalindrome(string someString)
{
string regexPattern = @"(?i)[^a-z]";
string replacement = "";
string amendedString = Regex.Replace(someString, regexPattern, replacement).ToLower();
string reverseAmendedString = new string(amendedString.Reverse().ToArray());
return amendedString.Equals(reverseAmendedString);
}
}