Here is a small function to split a string into sentences ending with a full stop. all sentences are then all stored in a List. anyway hope you find is us full.
csharp Code:
private List<string> SplitSentences(string source)
{
int x = 0;
string buffer = "";
char dot = '.';
List<string> _sentences = new List<string>();
while (x < source.Length)
{
switch (source[x])
{
//Skip new lines.
case '\n':
if (source[x + 1] == '\r')
{
//Look for carrige return and skip if found.
x += 2;
}
else
{
//Skip once.
x += 1;
}
break;
case '\r':
//Script new lines.
x += 1;
break;
case '.':
//Trim down the string.
buffer = buffer.Trim();
//Check string length.
if (buffer.Length != 0)
{
//Uppercase first letter
buffer = char.ToUpper(buffer[0]).ToString() +
buffer.Substring(1, buffer.Length - 1);
//Check for ending fullstop.
if (buffer[buffer.Length - 1] != dot)
{
buffer += dot;
}
//Add to list.
_sentences.Add(buffer);
buffer = "";
}
break;
default:
//Buid output string.
buffer += source[x];
break;
}
//INC Counter.
x++;
}
buffer = "";
return _sentences;
}
Example
csharp Code:
private void cmdsplit_Click(object sender, EventArgs e)
{
//Example.
List<string> sentences;
//Split string into sentences.
sentences = SplitSentences(textBox1.Text);
//Just an example fill up a list box.
foreach (string item in sentences)
{
listBox1.Items.Add(item);
}
}