Advertisement
martinvalchev

Extract_Sentences_by_Keyword

Feb 23rd, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace Extract_Sentences_by_Keyword
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string word = Console.ReadLine();
  15.             string input = Console.ReadLine();
  16.             string[] sentences = input.Split(new char[] { '.', '!', '?' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  17.             string pattern = $@"\b{word}\b";
  18.  
  19.             foreach (var sentence in sentences)
  20.             {
  21.                 if (Regex.IsMatch(sentence, pattern))
  22.                 {
  23.                     Console.WriteLine(sentence.Trim());
  24.                 }
  25.             }
  26.         }
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement