How can I split a string based on a string and have the resulting array contain the separators as well?
Example:
If my string = "Hello how are you.Are you fine?.How old are you?"
And I want to split based on string "you", then result I want is an array with items { "Hello how are", "you", ".Are", "you", "fine?.How old are", "you", "?" }
.
How can I get a result like this? I tried String.Split
and
string[] substrings = Regex.Split(source, stringSeparators);
But both are giving the result array without the occurrence of you
in it.
Also, I want to split only on the whole word you
. I don't want to split if you
is a part of some other words. For example, in the case Hello you are so young
, I want the result as { "Hello", "you", "so young" }
. I don't want to split the word young
to { "you", "ng" }
.