473,508 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting a QueryString-TYPE string to a NameValueCollection

Saw this requested awhile ago on Matthew Reynolds's blog here:

http://www.dotnet247.com/247referenc.../11/57944.aspx

Problem: often times I deal with querystring-formatted strings w/o the
actual HttpRequest object involved.
Solution: the function accepts such a querystring-type string and outputs a
NameValueCollection object
public static NameValueCollection NameValueCollection(string qs)
{
NameValueCollection nvc = new NameValueCollection();
//strip string data before the question mark
qs = qs.IndexOf('?')>0?qs.Remove(0,qs.IndexOf('?')+1):q s;
Array sqarr = qs.Split("&".ToCharArray());
for(int i=0;i<sqarr.Length;i++)
{
string [] pairs =
sqarr.GetValue(i).ToString().Split("=".ToCharArray ());
nvc.Add(pairs[0],pairs[1]);
}
return nvc;
}
Nov 17 '05 #1
0 1441

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3638
by: Johnny Carson | last post by:
I've got this PHP script working on one of my sites and now need an ASP version for my intranet. I don't know ASP, can anyone help out? Know of anyway to NOT have a blank browser window open...
3
17278
by: Arpan | last post by:
A link has the following URL: <a href="Page1.asp?cname=<%= Request.QueryString("cname") %>&cadd1=<%= Request.QueryString("cadd1") %>&cadd2=<%= Request.QueryString("cadd2") %>&cplace=<%=...
10
2846
by: jose.jeria | last post by:
I use the following to convert uppercase to lowercase: translate($queryString, 'ABCDE...', 'abcde...') But how can i convert the case for umlauts? öåä etc
4
19705
by: Raterus | last post by:
Howdy, Simple question, but I can't figure out how to do it. I have a a page which is called initially with a querystring. After I get the querystring values, I don't need the querystring to...
6
2887
by: Keith Patrick | last post by:
I have to do some programmatic redirects (in several pages) based on URLs I am given from an external source. The URLs have querystrings at the end, but one in particular is about 240 chars long,...
12
5276
by: Alex | last post by:
I have a question about determining if one QueryString keys exists. The idea is, if this key exists, than its presence is enough to indicate that its value is true. For example ... ...
1
1125
by: Keith Patrick | last post by:
I've got an app that does a ton of Response.Redirect's to bring up various pages. Due to some printer-friendly stuff we use, the URLs all have to pass their data in via the querystring. However,...
3
3116
by: Dan Sikorsky | last post by:
How can I get the Querystring passed to the Referring Page from its referrer? I don't want the querystring coming to my current page. I want the querystring that came to the referring page, so...
7
2516
by: fox | last post by:
Hi, Lacking javascript knowledge, I just realized why my project has a bug. I am using ASP to loop through a set of records while it creates URLs with a querystring that has a single value pair....
3
2147
by: pingsheng | last post by:
Dear all, I have a form with dynamically created input fields. These fields go to next page for submitting into SQL database. The thing is all fields are the same but 4 fields. So each record...
0
7224
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7118
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7323
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7493
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5625
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4706
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.