获取字符串后的所有文本直到下一次出现字符串?

时间:2011-03-25 00:45:14

标签: c# arrays string

如何在每次出现字符串后获取所有文本,例如,我必须遵循以下文本:

commonstring
text and more text and more
random text that may or may 
not be on multiple lines
commonstring
more random text that
will be after the common string

如何将其转换为

数组
{ "text and more text and more random text that may or may not be on multiple lines", "more random text that will be after the common string" } 

2 个答案:

答案 0 :(得分:1)

使用此String.Split重载:

string[] parts = s.Split(new[] { "commonstring" }, int.MaxValue, StringSplitOptions.None);

答案 1 :(得分:0)

你想要使用Regex.Split:

string[] result = Regex.Split(inputString, @"commonstring");