473,698 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I parse name/value pairs from a config string?

If, for example, I retrieve a connectionstrin g from a config file using
something like:

Value = ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];

This will return a string that is semi-colon delimited. If I want, say, to
retrieve the password from this string will I need to explicity parse it?
Jul 21 '05 #1
4 12663
Bill,
I normally use String.Split to separate each pair, then use String.Split
again to separate the pairs.

Optionally putting the name/value pairs into a HashTable or
NameValueCollec tion.

Instead of the second String.Split I've used String.IndexOf &
String.SubStrin g to split the pairs, as there should be only a single split
needed...

Hope this helps
Jay

"Bill" <nf*@nospam.com > wrote in message
news:Ot******** *****@TK2MSFTNG P12.phx.gbl...
If, for example, I retrieve a connectionstrin g from a config file using
something like:

Value = ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];

This will return a string that is semi-colon delimited. If I want, say, to
retrieve the password from this string will I need to explicity parse it?

Jul 21 '05 #2
Yep. You may use String.Split() to get individual ';' separated items and
another String.Split() (or String.StartsWi th() ) on the first set to get the
password.

HTH.

"Bill" <nf*@nospam.com > wrote in message
news:Ot******** *****@TK2MSFTNG P12.phx.gbl...
If, for example, I retrieve a connectionstrin g from a config file using
something like:

Value = ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];

This will return a string that is semi-colon delimited. If I want, say, to
retrieve the password from this string will I need to explicity parse it?

Jul 21 '05 #3
If you wanted to get really excited you could use Regular Expressions:

In VB.NET (I doubt the C# is a million miles away) :

'don't forget to import the namspace
Imports System.Text.Reg ularExpressions

'later...
'we're assuming a SQL Server connection string here and SQL Server
'Authentication
Dim regExp as new Regex("server=\ w*;")
Dim m Match

m = regExp.Match(st rDBConnectionSt ring, "pwd=\w*;")

If m.Success Then
'you've found it...
End If

Notice the "\w*" bit is searching for a "word" in the phrase searched.

This would work with the other bits of the connection string too by tweaking
the expression BUT I have found the "word" gets confused if your server is
being identified by an IP address instead of it's name...

Probably all those "."'s :)

al*****@yahoo.c om

"Bill" wrote:
If, for example, I retrieve a connectionstrin g from a config file using
something like:

Value = ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];

This will return a string that is semi-colon delimited. If I want, say, to
retrieve the password from this string will I need to explicity parse it?

Jul 21 '05 #4
Thanks... Reqular Expressions strikes me as the way to go.

"alaspin" <al*****@discus sions.microsoft .com> wrote in message
news:48******** *************** ***********@mic rosoft.com...
If you wanted to get really excited you could use Regular Expressions:

In VB.NET (I doubt the C# is a million miles away) :

'don't forget to import the namspace
Imports System.Text.Reg ularExpressions

'later...
'we're assuming a SQL Server connection string here and SQL Server
'Authentication
Dim regExp as new Regex("server=\ w*;")
Dim m Match

m = regExp.Match(st rDBConnectionSt ring, "pwd=\w*;")

If m.Success Then
'you've found it...
End If

Notice the "\w*" bit is searching for a "word" in the phrase searched.

This would work with the other bits of the connection string too by tweaking the expression BUT I have found the "word" gets confused if your server is
being identified by an IP address instead of it's name...

Probably all those "."'s :)

al*****@yahoo.c om

"Bill" wrote:
If, for example, I retrieve a connectionstrin g from a config file using
something like:

Value = ConfigurationSe ttings.AppSetti ngs["ConnectionStri ng"];

This will return a string that is semi-colon delimited. If I want, say, to retrieve the password from this string will I need to explicity parse it?

Jul 21 '05 #5

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

Similar topics

5
3312
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the document.cookie variable combine all cookie key=value pairs? All of the examples I've seen discuss referencing a specific cookie. I don't see how this is done. Cookies are usually named by the domain. If I want to reference a specific cookie, do I...
5
3224
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: someArray = 6; I know I can't get the same syntactic sugar as Perl offers, with the usage of a string as the array key surrounded by square brackets. I just want the general functionality, that's all. That is, a data container that will maintain...
21
2653
by: William Stacey [MVP] | last post by:
Anyone know of some library that will parse files like following: options { directory "/etc"; allow-query { any; }; // This is the default recursion no; listen-on { 192.168.0.225; }; forwarders { 4.2.2.2; }; };
1
3049
by: Bill | last post by:
I have strings returned from a config file that contain zero or more name/value pairs using a pattern like "name = value;" I want to extract the value of a given name (passwords, etc.). I want this to ignore whitespace in the pattern match and not be case sensitive. Anyone have a pattern that will do this?
4
508
by: Bill | last post by:
If, for example, I retrieve a connectionstring from a config file using something like: Value = ConfigurationSettings.AppSettings; This will return a string that is semi-colon delimited. If I want, say, to retrieve the password from this string will I need to explicity parse it?
5
3685
by: Navid Azimi | last post by:
What's the best way to parse a currency string to a decimal given the possibility of multiple currencies? That is, my numeric string can be ($12.00) or -£12.00; in either case I want -12.00 to be returned. I understand that this may be slightly difficult given non-symbol currency strings (F or Kr) but I figured that the CultureInfo should be able to take care of it somehow. The closest solution I came up with, short of iterating through...
1
5560
by: ozzii | last post by:
Hi, Does anybody know how to parse the name value pairs in a querystring contained in a variable with asp? for those of you who might be confused, what i am trying to do is basically I have a recordset paging script generated for a search page. I want to read all the search criteria in the querystring of this paging script into one variable and then parse it at the other end. The idea behind this is to avoid displaying the entire...
5
2301
by: simononestop | last post by:
Hi im totally new to perl this is my first go at using it (I normally use asp). I have set up a form with a cgi script from demon hosting. I have edited the script and the form works it sends me an email. however all the information is missing form the email I only get the first form text field?? #!/bin/perl # ------------------------------------------------------------
7
1394
by: Cirene | last post by:
I have a long string (MyString) with several token/value combinations. Here's an example... NAME: JOHN ADDRESS: 123 MAIN ST COUNTY: SOMEWHERE PHONE: 333-222-5151 x542 EMAIL: SOME@SOME.COM How can I easily parse out a few of these tokens? For example, if I want to get the COUNTY, or PHONE? I would think that the split function would work, but this doesn't seem to
0
8680
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...
0
9030
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8899
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,...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5861
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
4371
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...
1
3052
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
2335
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
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.