1

I am getting the current URL with:

   string url = HttpContext.Current.Request.Url.AbsoluteUri;
//url = blahblahblah.aspx?NUMBER=8798494651&FULLNAME=Ronald

After this, I want to use url.Split() to obtain the value after both equals signs. This would normally be straight forward but as you can see the first value has an obvious end character of '&' while the other does not. Furthermore, the FULLNAME value can always be different.

I have seen other Regex parsing questions/answers on here but of course they are all for specific cases.

Thanks in advance.

5
  • Try this: codeproject.com/Articles/9433/Understanding-CGI-with-C Commented Sep 24, 2015 at 23:02
  • Why not you retrieve value as::: var num = Request.QueryString["NUMBER"]; var name= Request.QueryString["FULLNAME"]; Commented Sep 24, 2015 at 23:13
  • @DCODE I tried that. It was not picking up the values. I would get an error that way. That is why I am thinking of parsing the current url instead Commented Sep 24, 2015 at 23:15
  • @JonathanScialpi then try option as below Commented Sep 24, 2015 at 23:17
  • @JonathanScialpi What error are you getting? Commented Sep 24, 2015 at 23:24

1 Answer 1

4

Try this

var uri = new Uri("blahblahblah.aspx?NUMBER=8798494651&FULLNAME=Ronald");
var query = HttpUtility.ParseQueryString(uri.Query);

var var1 = query.Get("NUMBER");
var var2 = query.Get("FULLNAME");
Sign up to request clarification or add additional context in comments.

1 Comment

that worked well thanks @DCODE

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.