473,789 Members | 3,060 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Splitting Name and Value Parameters

I have a string which is formated like this

Name1=Value1; Name2=Value2; Name3=Value3

I need to split this to an array of

Name1=Value1
Name2=Value2
Name3=Value3

What is the best way to split the Name and Values so I can place them
into an array.

Regards
Jeff

Mar 18 '07 #1
6 1585
Random thought; this matches the syntaz for a connection string, so
just set this as the ConnectionStrin g of a DbConnectionStr ingBuilder
instance, and you can parse the keys and item members. Sneaky but it
should work ;-p
Alternatively, you could use string.Split specifying new char[]
{'=',';'}

Marc

Mar 18 '07 #2
On Mar 18, 2:32 pm, "Marc Gravell" <marc.grav...@g mail.comwrote:
Random thought; this matches the syntaz for a connection string, so
just set this as the ConnectionStrin g of a DbConnectionStr ingBuilder
instance, and you can parse the keys and item members. Sneaky but it
should work ;-p
Alternatively, you could use string.Split specifying new char[]
{'=',';'}

Marc
The second method should also involve string.Trim() because there is
the chance of spaces between the semicolons.

Freiddy
http://fei.yuanbw.googlepages.com/
http://freiddy.blogspot.com/\

Mar 18 '07 #3
VJ
Good idea. Not sneaky at all, just being smart about what data we are
handling and trying to do quick, easy and efficient solution.

VJ

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** **************@ l75g2000hse.goo glegroups.com.. .
Random thought; this matches the syntaz for a connection string, so
just set this as the ConnectionStrin g of a DbConnectionStr ingBuilder
instance, and you can parse the keys and item members. Sneaky but it
should work ;-p
Alternatively, you could use string.Split specifying new char[]
{'=',';'}

Marc

Mar 18 '07 #4
Split on the semicolon, then loop through the output array splitting on the
equals sign.

Tom Dacon
Dacon Software Consulting

"Jeff Williams" <je***********@ hardsoft.com.au wrote in message
news:12******** *****@corp.supe rnews.com...
>I have a string which is formated like this

Name1=Value1; Name2=Value2; Name3=Value3

I need to split this to an array of

Name1=Value1
Name2=Value2
Name3=Value3

What is the best way to split the Name and Values so I can place them into
an array.

Regards
Jeff

Mar 18 '07 #5
On Sun, 18 Mar 2007 10:14:44 -0500, "VJ" <no***********@ yahoo.comwrote:
>Good idea. Not sneaky at all, just being smart about what data we are
handling and trying to do quick, easy and efficient solution.

VJ

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******* *************** @l75g2000hse.go oglegroups.com. ..
>Random thought; this matches the syntaz for a connection string, so
just set this as the ConnectionStrin g of a DbConnectionStr ingBuilder
instance, and you can parse the keys and item members. Sneaky but it
should work ;-p
Alternativel y, you could use string.Split specifying new char[]
{'=',';'}

Marc
Not if you want a maintenance programmer or debugging person to be able to
understand what you did.

Just my $.02 worth...

Good luck with your project,

Otis Mukinfus

http://www.otismukinfus.com
http://www.arltex.com
http://www.tomchilders.com
http://www.n5ge.com
Mar 19 '07 #6
Not if you want a maintenance programmer or debugging person to be able to
understand what you did.
There will be a lot less to debug in the first place if you re-use
tried-and-trusted code... and comments, e.g.

// expected input: key1=value1; key2=value2; key3=value3
// output: StringDictionar y of parsed values from input

// use DbConnectionStr ingBuilder to parse input string
DbConnectionStr ingBuilder builder = new DbConnectionStr ingBuilder();
StringDictionar y dict = new StringDictionar y();
builder.Connect ionString = value;
foreach(string key in builder.Keys) {
dict.Add(key, builder[key]);
}
Marc

Mar 19 '07 #7

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

Similar topics

11
3044
by: Andrew Thompson | last post by:
I have written a few scripts to parse the URL arguments and either list them or allow access to the value of any parameter by name. <http://www.physci.org/test/003url/index.html> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&that=this&when=now#21> <http://www.physci.org/test/003url/index.html?url=http://mybiz.com/&when=now> Before I go offering it in public (and writing it into any number of the 'development kits'...
11
1685
by: Steve Darby | last post by:
Can anyone help with this problem. I am attempting to dynamically draw a graph using data from a cookie. I have written the script to actually draw the graph, for which I hav created two arrays with the data I required preset into them. What I wish to do is split the cookie in which the data is stored and create two array from it. The function used to create the cookie is as follows :function SetCookie(name, value) {...
4
16985
by: Todd Perkins | last post by:
Hello all, surprisingly enough, this is my first newsgroup post, I usually rely on google. So I hope I have enough info contained. Thank you in advance for any help! Problem: I am getting this error when I try to pull up my edit page to display the current database information in the form, and then edit it on click:
0
1160
by: BPNA | last post by:
I've encountered a problem with the SmtpMail.Send .Net framework 1.1 call in Windows 2003. What I'm seeing are 4 junk characters added at a consistent message position which happens at the 989th character (and others) in the email body. The characters being added are <!><CR><LF><space> which the "!" character breaks my HTML email form parameters (name or value depending on a dynamic HTML form). I setup a special Win2k3 box with all the...
2
1320
by: John Kotuby | last post by:
Hi All, I am trying to move my experience with VB6 and ADO over to VB.NET. I am having difficulty with assigning values to SQL parameters. In classic ADO a value could be assigned to a parameter by referring to it with the index as the parameter name in quotes. Here is some code to illustrate the problem. Dim parameters As SqlParameter() = { _ New SqlParameter("@DocRef", SqlDbType.VarChar, 30), _ New SqlParameter("@EdiDocID",...
11
3490
by: Alexander Walker | last post by:
Hello I would like to write a method that allows me to pass a reference to an instance of a class, the name of a property of that class and a value to set that property to, the method would then set the property of the instance to the value here is an example of what the method might look like public void SetProperty(object instance, string property, object value) {
1
2509
by: John Kotuby | last post by:
Hi all, I am working on porting an application from VB6 to VB.NET 2003 and am running into some problems. When declaring and populating the parameters for a SQL Stored Procedure by using the SQLParameter() collection and trying to reference a particular parameter by name rather than index I get a Type Conversion error. But when declaring a SqlClient.SqlCommand object and then adding the parameters to the command object parameters...
2
14439
by: vvenk | last post by:
Hello: I wrote a small program to insert a row into an Oracle Table: CREATE TABLE case_list (case_list_name_c VARCHAR2(100) NOT NULL, expiry_dt DATE NOT NULL, days_to_expire_n NUMBER(*,0), created_dt DATE DEFAULT SYSDATE, created_by_n NUMBER)
4
3823
by: Steven D'Aprano | last post by:
I'm trying to split a URL into components. For example: URL = 'http://steve:secret@www.domain.com.au:82/dir" + \ 'ectory/file.html;params?query#fragment' (joining the strings above with plus has no significance, it's just to avoid word-wrapping) If I split the URL, I would like to get the following components:
0
9665
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10139
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9983
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6768
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5417
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5551
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4092
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 we have to send another system
2
3697
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2909
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.