473,387 Members | 1,492 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Convert string or stringbuilder to name/value collection

I have a string with name value collections (i.e. &foo=1&foo2=2)

Can I convert this string to some kind of name/value collection so I
can access the values with something like :

params["foo"] = 1;

Thanks,

Nov 19 '05 #1
2 7262
Sure. You can use System.Collections.Specialized.NameValueCollection . First,
split the string into an array of strings, by splitting on the "&"character.
Then loop through the array of strings, splitting each one on the "="
character, and adding a new Item to the Collection. Example:

string source = "this=that&these=those&them=Something Else";
NameValueCollection myValues = new NameValueCollection();
string[] aryStrings = source.Split(new char[] {'&']});
string[] nameAndValue;
foreach (string s in aryStrings)
{
nameAndValue = s.Split(new char[] {'='});
myValues.Add(nameAndValue[0], nameAndValue[1]);
}

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

<np*****@gmail.com> wrote in message
news:11**********************@g49g2000cwa.googlegr oups.com...
I have a string with name value collections (i.e. &foo=1&foo2=2)

Can I convert this string to some kind of name/value collection so I
can access the values with something like :

params["foo"] = 1;

Thanks,

Nov 19 '05 #2
Great - thanks Kevin!

Nov 19 '05 #3

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

Similar topics

2
by: Peter Kwan | last post by:
Hi, I believe I have discovered a bug in Python 2.3. Could anyone suggest a get around? When I tested my existing Python code with the newly released Python 2.3, I get the following warning: ...
5
by: JimMenees | last post by:
I know there's an easy answer to this which is escaping me: -------------------------------------------------------------------------- ----------------------- I have clickable thumb images which...
5
by: MLH | last post by:
I have this expression in a query ... Trim$(Left$(,-1)) It evaluates to "1/16" How can I convert that to the numeric value 0.0625?
3
by: TR | last post by:
A company that lets affiliates search its database assumes that affiliates will paste code, which looks something like this, into their web pages: <form method="GET" name="search_5"...
0
by: Greg | last post by:
There appears to be an issue with one of the values I send to a remote server in a name value collection. if it is over 600, I get the expected result, if under I get an error returned from the...
0
by: David Lozzi | last post by:
Howdy, I'm trying to get the values from a string of name/value pairs. I'm using a RegEx (I'm very new to RegEx) expression as seen below Dim regExp As Regex Dim m As Match m =...
1
by: mehdi_mousavi | last post by:
Hi folks, Consider a string that's defined under VS2005 resource editor as myField with the value of myValue. To access the value, I could easily use the Properties.Resources class, for example:...
3
by: Jeff User | last post by:
Hi all vs2003, .NET1.1 I would like to store alignment values in SQL Server db and then use them in C# to set values of cells in tables. Problem is that a string variable will not work. Is...
1
by: shyamal | last post by:
can anyone pls help me in visual basic to convert string data to integer. I am getting encoder position pulse data through Rs232 as string like "-450". I need to calculate the actual displacement...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...

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.