Normally I wouldn't do this, but it was kind of fun :)
class Program
{
static void Main(string[] args)
{
List<string> palens = Palendromerize("ABCBAHELLOHOWRACECARAREYOUIAMAIDOINGGOOD");
foreach (string palen in palens)
Console.WriteLine("Palendrome: " + palen);
Console.ReadKey();
}
static List<string> Palendromerize(string s)
{
string reverseStr = new string(s.Reverse().ToArray());
List<string> retVal = new List<string>();
for (int i = 0; i < s.Length; i++)
{
string s1 = new string(' ', s.Length - i - 1) + s;
string s2 = new string(' ', i) + reverseStr;
string matches = string.Empty;
for (int x = 0; x < Math.Min(s1.Length, s2.Length); x++)
{
if (s1[x] == s2[x])
matches += s1[x];
else
matches += ' ';
}
string[] palens = matches.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
for (int m = 0; m < palens.Length; m++)
if (palens[m].Length >= 3)
retVal.Add(palens[m]);
}
return retVal;
}
}
Output:
Palendrome: ABCBA
Palendrome: OHO
Palendrome: RACECAR
Palendrome: ARA
Palendrome: RAR
Palendrome: IAMAI
Basically this works by sliding each string along the other one, only paying attention to the pieces of the string that match up. Then you take any characters that match positions in both strings and add them to an array. Split the array removing empty entries. Then since the minimum length of a palendrome is 3, filter out the ones that are shorter and then add them to the results list.