PC Review


Reply
Thread Tools Rate Thread

Converting a QueryString-TYPE string to a NameValueCollection

 
 
Yuri Vanzine
Guest
Posts: n/a
 
      18th Aug 2003
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):qs;
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;
}


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Split string to NameValuecollection Alex Schlecht Microsoft C# .NET 5 15th Mar 2006 03:37 PM
How to convert NameValueCollection to string? =?Utf-8?B?d2FsdGVy?= Microsoft Dot NET Framework 0 31st Aug 2005 01:58 PM
exposing NameValueCollection Property through ASPX page ? (string representation of its values) sonic Microsoft ASP .NET 1 7th Jan 2005 07:15 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Jon Skeet Microsoft C# .NET 0 31st Jul 2003 08:38 PM
Re: Converting a string to a string that contains the ASCII values of each letter in the origional string Frank Oquendo Microsoft C# .NET 0 31st Jul 2003 08:36 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:04 PM.