Search code examples
c#textsplit

Split text into sentences in C#


I want to divide a text into sentences. A sentence ends with (dot) or ? or ! followed by one or more whitespace characters followed and the next sentence starts with an uppercase letter.

For example:

First sentence. Second sentence!

How can I do that?


Solution

  • What languages do you want to support? For example, in Thai there are no spaces between words and sentences are separated with space. So, in general, this task is very complex. Also consider the useful comment by Fredrik Mörk.

    So, at first you need to define set of rules on what "sentence" is. Then you are welcome to use one of the suggested solutions.