1

Possible Duplicate:
Most optimal way to parse querystring within a string in C#

I have the following url which I get as an input.

string strInput = @"http://ping.com/default.aspx?
val=88.998~98.3399&val=12.55_14.55&val=8.299&val=7.299&val=9.299";

I want to extract values 88.998 ,98.3399 and 7.299.Sometimes these values might be empty. I tried the pattern @"(?\=<val1>\d+\~$)" for extracting 88.998 , but it didn't work. And also I am not able to get other two values 98.3399 and 7.299.

Community
  • 1
  • 1
krrishna
  • 2,050
  • 4
  • 47
  • 101
  • 2
    Don't reinvent the wheel! Use a library. What you want to do is called *URL parsing*, specifically, the bit after the question mark is called the *querystring*. – Colonel Panic Jan 26 '13 at 18:44
  • What is your actual problem? Trying to pars Url with Regex adds more than standard +1 problem - ["want to do it with regex - now you have two problems"](http://regex.info/blog/2006-09-15/247). – Alexei Levenkov Jan 26 '13 at 18:44

1 Answers1

2

See https://stackoverflow.com/a/1206659/284795

You can do it this way:

using System.Collections.Specialized;

NameValueCollection query = HttpUtility.ParseQueryString(queryString);
Response.Write(query["id"]);

Hope it helps.

Community
  • 1
  • 1
Colonel Panic
  • 132,665
  • 89
  • 401
  • 465