Advertisement
Asenval

Untitled

Feb 1st, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. class ExtractAllPalindromes
  4. {
  5.     static void Main()
  6.     {
  7.         string str = "ABBA ffeerer efffefee, lamal ererfe exeff exe ";
  8.         //Console.WriteLine("Insert string");
  9.         //string str = Console.ReadLine();
  10.         string[] arrayOfStrings = str.Split(new char[] { ' ', '.', ',', '!', '?' }, StringSplitOptions.RemoveEmptyEntries);
  11.         for (int i = 0; i < arrayOfStrings.Length; i++)
  12.         {
  13.             str = arrayOfStrings[i];
  14.             bool IsPalindrom = false;
  15.             for (int j = 0; j < str.Length / 2; j++)
  16.             {
  17.                 if (str.Substring(j, 1) == str.Substring(str.Length - 1 - j, 1))
  18.                 {
  19.                     IsPalindrom = true;
  20.                 }
  21.                 else
  22.                 {
  23.                     IsPalindrom = false;
  24.                     break;
  25.                 }
  26.             }
  27.             if (IsPalindrom == true && str.Length > 1)
  28.                 Console.WriteLine(str);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement