NonaG

ExtractSentencesByKeyword

Feb 8th, 2017
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 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. class ExtractSentencesByKeyword
  9. {
  10. static void Main()
  11. {
  12. var word = Console.ReadLine().ToLower();
  13. var input = Console.ReadLine().Split('!', '.', '?');
  14. var pattern = @"\b([word]+)\b";
  15. var replaced = pattern.Replace("word", word);
  16. var reg = new Regex(replaced);
  17. for (int i = 0; i < input.Length; i++)
  18. {
  19. var matches = reg.Matches(input[i]);
  20. foreach (Match match in matches)
  21. {
  22. if (match.Success==true)
  23. {
  24. Console.WriteLine(input[i]);
  25. }
  26. }
  27. }
  28.  
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment