C# – How to split this string into an array


My string is as follows:

smtp:jblack@test.com;SMTP:jb@test.com;X400:C=US;A= ;P=Test;O=Exchange;S=Jack;G=Black;

I need back:

X400:C=US;A= ;P=Test;O=Exchange;S=Jack;G=Black;

The problem is the semi-colons seperate the addresses and also part of the X400 address. Can anyone suggest how best to split this?

PS I should mentioned the order differs so it could be:

X400:C=US;A= ;P=Test;O=Exchange;S=Jack;G=Black;;smtp:jblack@test.com;SMTP:jb@test.com

There can be more than 3 address, 4, 5.. 10 etc including an X500 address, however they do all start with either smtp: SMTP: X400 or X500.

Best Solution

EDIT: With the updated information, this answer certainly won't do the trick - but it's still potentially useful, so I'll leave it here.

Will you always have three parts, and you just want to split on the first two semi-colons?

If so, just use the overload of Split which lets you specify the number of substrings to return:

string[] bits = text.Split(new char[]{';'}, 3);