Return to Snippet

Revision: 23374
at February 5, 2010 01:08 by ajit555


Initial Code
Dictionary<String, String> result = new Dictionary<string, string>();
String urlString = "http://www.jwize.com?param1=valu1&param2=value2";

var query = from match in urlString.Split('?').Where(m => m.Contains('='))
                .SelectMany(pr => pr.Split('&'))
            where match.Contains('=')
            select new KeyValuePair<string, String>(
                match.Split('=')[0],
                match.Split('=')[1]);
query.ToList().ForEach(kvp => result.Add(kvp.Key, kvp.Value));

Initial URL
http://snipplr.com/view/27185/get-url-parameters-using-linq/

Initial Description

                                

Initial Title
Get URL Parameters using LINQ

Initial Tags
url

Initial Language
C#