Skip to content

Instantly share code, notes, and snippets.

@Cheesebaron
Created August 12, 2014 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Cheesebaron/7abd5106a10c464a10e9 to your computer and use it in GitHub Desktop.
Save Cheesebaron/7abd5106a10c464a10e9 to your computer and use it in GitHub Desktop.
Just a simple LINQ query to split an URL's query into a key/value dictionary. Useful in PCL's where there is not HttpUtility class.
static Dictionary<string, string> QueryToKeyValueDictionary(string url)
{
return
url.Substring(url.IndexOf('?') + 1)
.Split('&')
.Select(pair => pair.Split('='))
.ToDictionary(val => val[0], val => Uri.UnescapeDataString(val[1]));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment