0

I have a querystring:

...default.aspx?date=May%202012

I want to get may and 2012 separately from that using:

Request.querystring("date")

....something similar for each.

Is this possible?

1 Answer 1

2

You can use HttpUtility.UrlDecode:

Dim dateParam = HttpUtility.UrlDecode(Request.QueryString("date"))
Dim dateParts = dateParam.Split(" "c)
Dim month = dateParts(0)
Dim year = dateParts(1)

C#

var dateParam = HttpUtility.UrlDecode(Request.QueryString["date"]);
var dateParts = dateParam.Split(' ');
var month = dateParts[0];
var year = dateParts[1];

Edit: As @Servy has commented HttpUtility.UrlDecode is redundant above since Request.QueryString decodes it implicitely, but it doesn't hurt ;-)

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

6 Comments

@Servy from question: I want to get may and 2012 separately
Request.QueryString already does a UrlDecode, it shouldn't be decoded again.
@Servy it is not related with url encoding/decoding. date parameter contains May 2012 (in decoded form). So you have to split it to get the May and 2012 separately.
@Servy: Edited my answer. I assume that OP just didn't know how to split both parts.
I got the above example to work with HttpUtility.UrlDecode, but am curious as to how I would split the querystring without it?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.