2

I have a string that is the contents of a webpage in this format :

   value=foo&value1=bar&value2=foobar

What I would like to know is, is there a built-in way to convert this into an object/list of object/whatever so that I can loop through or access the values by keyname

I know I can split on '&', and then split on '=', but I believe there is a built-in way to do this, I just do not know what it is.

The language I am working in is C#.

Kraang Prime
  • 9,981
  • 10
  • 58
  • 124

1 Answers1

2

You can use HttpUtility.ParseQueryString.

Eg.

NameValueCollection values = HttpUtility.ParseQueryString("value=foo&value1=bar&value2=foobar");
Steve
  • 9,335
  • 10
  • 49
  • 81
  • What do I need to reference as `using`, I tried `using System.Web;` and HttpUtility doesn't seem to exist. --- edit: Had to add a reference to System.Web as well since the built-in System.Web was missing this. – Kraang Prime May 06 '15 at 01:26