Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- class SentencesExtractRegex
- {
- static void SubstringCounter(string textTemp, string targetTemp)
- {
- string text = textTemp; // toUpper
- string target = targetTemp; // toUpper
- StringBuilder sb = new StringBuilder();
- string[] parts = Regex.Split(text, @"\.\n|\. ");
- sb.AppendFormat(@"\b{0}\b", target);
- string pattern = sb.ToString();
- foreach (var sentence in parts)
- {
- Match match = Regex.Match(sentence, pattern);
- bool sign = false;
- while (match.Success)
- {
- sign = true;
- match = match.NextMatch();
- }
- if (sign == true)
- {
- Console.WriteLine(sentence);
- }
- }
- return;
- }
- static void Main()
- {
- string someText = "We are living in an yellow submarine. We don't have anything else. Inside the submarine is very tight. So we are drinking all the day. We will move out of it in 5 days.";
- string target = "in";
- SubstringCounter(someText, target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement