You can replace every string of the list in the original string with an added control character, and then split on that caracter. For instance, your original string:
List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar
Need to become:
List_1 fooo asdf;List_2 bar fdsa;XList_3 fooo bar
Which will later be split based on ;, producing the desired result. For that, i use this code:
string ori = "List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar"
foreach (string word in l_lstValues) {
ori = ori.Replace(word, ";" + word);
}
ori = ori.Replace(" ;", ";"); // remove spaces before ;
ori = Regex.Replace(ori, "^;", ""); // remove leading ;
return (ori.split(";"));
You could also assemble the following regular expression:
(\S)(\s?(List_1|XList_3|List_2))
The first token (\S) will prevent replacing the first occurrence, and the second token \s? will remove the space. Now we use it to add the ;:
string ori = "List_1 fooo asdf List_2 bar fdsa XList_3 fooo bar"
string regex = "(\S)(\s?(" + String.Join("|", l_lstValues) + "))";
ori = Regex.Replace(ori, regex, "$1;$3");
return (ori.split(";"));
The regex option is a bit more dangerous because the words can contain scape sequences.