Skip to content

Instantly share code, notes, and snippets.

@bjoerntx
Created May 2, 2024 14:45
Show Gist options
  • Save bjoerntx/f89b0cb0105ba4f280018b25d5eaa68e to your computer and use it in GitHub Desktop.
Save bjoerntx/f89b0cb0105ba4f280018b25d5eaa68e to your computer and use it in GitHub Desktop.
public static List<string> ExtractSentences(string input)
{
List<string> sentences = new List<string>();
// Use regular expression to split the input string into sentences but keep white spaces
string pattern = @"([.!?])";
// split the input string into sentences with the delimiters
string[] splitSentences = Regex.Split(input, pattern);
// Trim each sentence and remove empty strings
foreach (string sentence in splitSentences)
{
sentences.Add(sentence);
}
return sentences;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment