Splitting a string which contain multiple symbols to get specific values

Posted by Eon Rusted du Plessis on Stack Overflow See other posts from Stack Overflow or by Eon Rusted du Plessis
Published on 2012-03-20T12:09:59Z Indexed on 2012/03/20 17:29 UTC
Read the original article Hit count: 176

Filed under:
|

I cannot believe I am having trouble with this following string

String filter = "name=Default;pattern=%%;start=Last;end=Now";

This is a short and possibly duplicate question, but how would I split this string to get:

string Name = "Default";
string Pattern = "%%" ;
string start = "Last" ;
string end = "Now" ;

Reason why I ask is my deadline is very soon, and this is literally the last thing I must do. I'm Panicking, and I'm stuck on this basic command. I tried:

pattern = filter.Split(new string[] { "pattern=", ";" },
                       StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the pattern
startDate = filter.Split(new string[] { "start=", ";" },
                         StringSplitOptions.RemoveEmptyEntries)[1]; //Gets the start date

I happen to get the pattern which I needed, but as soon as I try to split start, I get the value as "Pattern=%%"

What can I do?

Forgot to mention The list in this string which needs splitting may not be in any particular order . this is a single sample of a string which will be read out of a stringCollection (reading these filters from Properties.Settings.Filters

© Stack Overflow or respective owner

Related posts about c#

Related posts about split