Posted By

ajit555 on 02/05/10


Tagged

url String Linq


Versions (?)

Who likes this?

4 people have marked this snippet as a favorite

mamona
digiteyes
tonicglop
mheinrich


Get URL Parameters using LINQ


 / Published in: C#
 

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

  1. Dictionary<String, String> result = new Dictionary<string, string>();
  2. String urlString = "http://www.jwize.com?param1=valu1&param2=value2";
  3.  
  4. var query = from match in urlString.Split('?').Where(m => m.Contains('='))
  5. .SelectMany(pr => pr.Split('&'))
  6. where match.Contains('=')
  7. select new KeyValuePair<string, String>(
  8. match.Split('=')[0],
  9. match.Split('=')[1]);
  10. query.ToList().ForEach(kvp => result.Add(kvp.Key, kvp.Value));

Report this snippet  

You need to login to post a comment.