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.

2
  • 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. Commented Jan 26, 2013 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". Commented Jan 26, 2013 at 18:44

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

+1 for finding the right question. Consider editing and adding the remaining part to use String.Split("~") to separate pairs of numbers from query parameter...
Looks like 100% copy paste from stackoverflow.com/a/1206659/284795

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.