parsing a name/value querystring string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

i have a querystring i need to parse manually with code

c=12345&f=67890&d=12345

and retrive the values of the variables c,f, and d, etc.

is there a a way to use a collection to parse this for me without having to manually split this string up?

thanks!

Fid
 
Well, if you have the complete URL you can pass it into the Uri class which
parses the content.

Fid said:
i have a querystring i need to parse manually with code

c=12345&f=67890&d=12345

and retrive the values of the variables c,f, and d, etc.

is there a a way to use a collection to parse this for me without having
to manually split this string up?
 
Hey,

The Request.QueryString method already returns a NameValueCollection for
which you could use.

Otherwise you can just use Request.QueryString["c"].ToString();

If you were asking something different, please reply to this post.

Tom
Blue Pen Solutions
http://www.bluepensolutions.com

Fid said:
i have a querystring i need to parse manually with code

c=12345&f=67890&d=12345

and retrive the values of the variables c,f, and d, etc.

is there a a way to use a collection to parse this for me without having
to manually split this string up?
 
On the receiving page you can get the value off the querystring with
code something like this:
Dim nvc As NameValueCollection
nvc=Request.QueryString

Here's more info:
http://msdn.microsoft.com/library/d...sSpecializedNameValueCollectionClassTopic.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net



Fid said:
i have a querystring i need to parse manually with code

c=12345&f=67890&d=12345

and retrive the values of the variables c,f, and d, etc.

is there a a way to use a collection to parse this for me without having
to manually split this string up?
 
Thanks for the replie

actually what i needed was a was to parse a string that merely looks like a querystring, but is not actually the Requst.QueryString object

what i am doing is receiving an a QueryString which has been encrypte
when I decrypt the string what i am left with i

MyString = "c=12345&f=12345&d=12345

i want to convert MyString to the separate key/values
I tried using the NameValueCollection, but keep getting errors trying to load a string or array into it

I cannot use the Request.QueryString object cause all that has is one encryted variabl

thanks again!
 
Based on your stated non-querystring need, I would suggest using a
nested split

Split MyString on the & character and you are left with an array of 3
items:

"c=12345"
"f=12345"
"d=12345"

Now on each of those, do a split using the "=" as the split character.
 
air code:

HashTable args = new HashTable();
foreach (string arg in myString.Split('&'))
{
string[] parts = arg.Split('=');
args.Add(parts[0],HttpUtility.UrlDecode(parts[1]);
}

-- bruce (sqlwork.com)

Fid said:
Thanks for the replies

actually what i needed was a was to parse a string that merely looks like
a querystring, but is not actually the Requst.QueryString object.
what i am doing is receiving an a QueryString which has been encrypted
when I decrypt the string what i am left with is

MyString = "c=12345&f=12345&d=12345"

i want to convert MyString to the separate key/values.
I tried using the NameValueCollection, but keep getting errors trying to
load a string or array into it.
 
Back
Top