Home > DeveloperSection > Forums > Convert query string to key-value pair
Jeet Verma
Jeet Verma

Total Post:110

Posted on    September-03-2014 11:17 PM

 ASP.Net ASP.Net 

 1 Reply(s)
 1088  View(s)
Rate this:

If I have a string like so:


is there a method in C# that can convert that to a key-value pair similar to Request.QueryString?

Sumit Kesarwani

Total Post:378

Posted on    September-03-2014 11:40 PM


You can also use the ToDictionary() method:

var input = "Name=Irwin&Home=Caribbean&Preference=Coffee";

var items = input.Split(new[] { '&' });

var dict = items.Select(item => item.Split(new[] {'='})).ToDictionary(pair => pair[0], pair => pair[1]);

Don't want to miss updates? Please click the below button!

Follow MindStick