Question

I have a string that contains ?action=a&current=b&something=c i want to create a variable that i can do val = mymap['current']; Is there something in C# to parse this? or do i need to use a string.split and write my own func?

-edit- solved thanks to REA_ANDREW and Guy Starbuck (from the other thread).

using System.Web;
using System.Collections.Specialized;
//add System.Web reference to project
NameValueCollection q = HttpUtility.ParseQueryString(link.Substring(link.IndexOf("?")+1));
//value = q["key"]
Was it helpful?

Solution

This question shows a really fit for purpose method:

How to parse a query string into a NameValueCollection in .NET

using System.Collections.Specialized;

Andrew

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top