473,406 Members | 2,377 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,406 software developers and data experts.

Conerting String into Collection

14
Hi All,

Can I use "DirectCast" or "Ctype" to convert a string into NameValueCollection in VB.Net?

Example I want to convert the string "a=200&b=300" to NameValueCollection class using inbuilt method.

Don't want to go for split option.

Please let me know ASAP

Apurva G
Apr 3 '08 #1
2 1224
Plater
7,872 Expert 4TB
No.
Split would be the prefered method. If there were a method, it would probably use Split().
Apr 3 '08 #2
balabaster
797 Expert 512MB
I provided a method for this in the following thread:

http://bytes.com/forum/thread790709.html

It still relies on the Split() function, however, as far as your procedural code goes, it might be a little clearer. I built a class called NameValueCollectionEx that takes a string in the format you specified after which it functions as if it were a regular NameValueCollection object...with the exception that you can then return all the items in the collection as another data string.

Expand|Select|Wrap|Line Numbers
  1. Dim oNVC As New NameValueCollectionEx("Value1=1&Value2=2&Value3=3")
  2.  
  3. 'You can then reference items in the collection like:
  4. Dim Val1 As String = oNVC("Value1")
  5. Dim Val2 As String = oNVC("Value2")
  6. Dim Val3 As String = oNVC("Value3")
  7.  
  8. 'Viewing items in the collection as a NameValue string:
  9. Dim sOut As String = oNVC.DataString
  10. 'Output would be
  11. ' "Value1=New Value&Value2=2&Value3=3"
  12.  
  13. 'Modifying items
  14. oNVC("Value1") = "New Value"
  15.  
  16. 'Removing items:
  17. oNVC.Item("Value2").Remove
  18. Dim sOut As String = oNVC.DataString
  19. ' Output would be
  20. ' "Value1=New Value&Value3=3"
  21.  
  22. 'Adding items:
  23. oNVC.Add("Value1", "FirstItem")
  24. oNVC.Add("Value2", "SecondItem")
  25. oNVC.Add("Value3", "ThirdItem)
Apr 3 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel...
5
by: SpotNet | last post by:
Hello NewsGroup, I have a custom class and a collection for that custom class that inherits CollectionBase. As such; public class MyClass { private string datamember1 = string.Empty,...
2
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection...
3
by: Shimon Sim | last post by:
I have control. One of the properties is implemented as StringCollection. I didn't use any Editor attribute for it. During Design time system shows dialog similar to Items in DropDownList but Add...
5
by: deko | last post by:
Is there an accepted or standard way to get a unique name given a string and the collection in which it needs to be unique? Should I use a HashTable? Other options? Here's a first crack: ...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
3
by: jacob navia | last post by:
Abstract: Continuing the discussion about abstract data types, in this discussion group, a string collection data type is presented, patterned after the collection in C# and similar languages...
8
by: Tanzen | last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having come from an VB for Access background, I'm finding it a big learning curve. I have been working through several e-books which...
2
by: Jordan S. | last post by:
Using .NET 3.5... I have the following class: class NodeDescriptor { // Properties only in this class public int NodeID { get; private set; } public int ParentNodeID { get; private set; }...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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
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,...

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.