I'm trying to split a string into an array around words in a string array. Right now, I'm using myString.Split(arrayOfWordsToSplitOn, StringSplitOptions.RemoveEmptyEntries), which splits the string, but doesn't include the actual word that it is splitting on.
For example, if I have the string "My cat and my dog are very lazy", and a string array {"cat", "dog"}, right now it returns {"My", "and my", "are very lazy"}.
However, I would like to have the final output be {"My", "cat", "and my", "dog", "are very lazy"}. Is there any way to do this?
String.Splitapproach does the latterRegex.Split(s, string.Format(@"\b({0})\b", string.Join("|", arrayOfWordsToSplitOn)))