Dimoto

4. Extract Sentences by Keyword

Jun 3rd, 2016
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class ExtractSentencesByKeyword
  8. {
  9.  
  10.     static void Main()
  11.     {
  12.         char[] seperators = ".!?".ToCharArray();
  13.         //char letter = 'A';
  14.         //char[] seperatorsForSent = new char[177];
  15.         //for (char i = (char)0; i <= 176; i++)
  16.         //{
  17.         //    if (!(i >= 65 && i <= 90 || i >= 97 && i<= 122 || i >= 48 && i <= 57 || i == 45))
  18.         //    {
  19.         //        seperatorsForSent[i] = i;
  20.         //    }
  21.         //}
  22.         string word = Console.ReadLine();
  23.         List<string> text = Console.ReadLine().Split(seperators).ToList();
  24.        
  25.  
  26.         List<string[]> sentanses = new List<string[]>();
  27.  
  28.         for (int i = 0; i < text.Count; i++)
  29.         {
  30.             text[i] = text[i].Trim();
  31.             string[] sentans = text[i].Split();
  32.            
  33.             if (sentans.Contains(word))
  34.             {
  35.                 sentanses.Add(sentans);
  36.             }
  37.         }
  38.  
  39.         foreach (var sentans in sentanses)
  40.         {
  41.             Console.WriteLine(string.Join(" ", sentans));
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment