Possible Duplicate:
How do I split a string by strings and include the delimiters using .NET?
I'm trying to split a paragraph into sentences, using the String.split(_separators) method, but I want it to return my separators too.
static char[] _separators = { '.', '?', '!' };
string[] sentences = parag.Split(_separators);
lets say my parag is: "Thank you. For helping me!"
It will return
- Thank you
- For helping me
I want it to return something like this
- Thank you
- .
- For helping me
- !
I never used regex, is there a way this can be done using regex?
I tried regex and here how it works.
static string _separators = @"(\.)+|(\?)+|(\!)+|(\,)+|(\;)+";
string [] sentences = Regex.Split(phrase, pattern);
PS: I added the + to group the same separator together