SHARE
TWEET

02.Extract Sentences by Keyword

a guest Oct 28th, 2017 176 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02.ExtractSentencesByKeyWord
  5. {
  6.     class ExtractSentencesByKeyWord
  7.     {
  8.         static void Main()
  9.         {
  10.             string word = Console.ReadLine();
  11.             Regex pattern = new Regex($@"\b[^.?!]+\b {word} \b[^.?!]+\b");
  12.  
  13.             string text = Console.ReadLine();
  14.  
  15.             MatchCollection matches = pattern.Matches(text);
  16.  
  17.             foreach (Match match in matches)
  18.             {
  19.                 string sentence = match.Value.Trim();
  20.                 Console.WriteLine(sentence);
  21.             }
  22.         }
  23.     }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top