MiroslavKisov

ExtractSentencesByKeyword

Oct 29th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 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 _02.ExtractSentencesByKeyword
  9. {
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             string word = Console.ReadLine();
  15.             var pattern = @"\b" + word + @"\b";
  16.             string[] sentences = Console.ReadLine()
  17.                 .Split(new char[] { '.', '!', '?' },StringSplitOptions.RemoveEmptyEntries)
  18.                 .ToArray();
  19.             Regex regex = new Regex(pattern);
  20.             for (int i = 0; i < sentences.Length; i++)
  21.             {
  22.                 Match match = regex.Match(sentences[i]);
  23.                 if (match.Success)
  24.                 {
  25.                     Console.WriteLine(sentences[i].TrimStart());
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment