Created
July 29, 2012 08:59
-
-
Save aturgarg/3196850 to your computer and use it in GitHub Desktop.
Dictionary from querystring
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Parses a query string into a dictionary collection | |
/// </summary> | |
/// <param name="queryString">the query string to parse</param> | |
/// <returns>a dictionary collection of querystring items</returns> | |
public static Dictionary<string, string> ParseQueryString(string queryString) | |
{ | |
Dictionary<string, string> nameValueCollection = new Dictionary<string, string>(); | |
string[] items = queryString.Split('&'); | |
foreach (string item in items) | |
{ | |
if (item.Contains("=")) | |
{ | |
string[] nameValue = item.Split('='); | |
if(nameValue[0].Contains("?")) | |
nameValue[0] = nameValue[0].Replace("?",""); | |
nameValueCollection.Add(nameValue[0], System.Net.HttpUtility.UrlDecode(nameValue[1])); | |
} | |
} | |
return nameValueCollection; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment