user556396
user556396

Reputation: 597

Get all text after a string until next occurrence of the string?

How can i get all the text after every occurrence of a string for example, I have to following text:

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

How can I make that into an array of

{ "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" } 

Upvotes: 0

Views: 992

Answers (2)

Thomas Levesque
Thomas Levesque

Reputation: 292455

Use this String.Split overload:

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

Upvotes: 1

Andrew Cooper
Andrew Cooper

Reputation: 32576

You'll want to use Regex.Split:

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

Upvotes: 0

Related Questions