Link to home
Start Free TrialLog in
Avatar of Andy Green
Andy GreenFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Extract string values from app.config

I have the following in my app.config:

<add key="Message" value="Calling {client} to {room}" />

Both Client & Room are written in as variabless fom my code

I can read the string, but how would I extract the values for client & room.

I can use 2 additional strings as well as the full version, is there an easy way to get the values back.

Andy
Avatar of Rajar Ahmed
Rajar Ahmed
Flag of India image

Try this
<add key="Message" value ="Calling {0} to {1}"/>


Response.Write(String.Format(ConfigurationManager.AppSettings("Message"), "Client", "Room"))

Open in new window

Avatar of Andy Green

ASKER

Thanks but I'm not sure how this works.

I have the values written into the app.config, and want to get them back out.

for example my value is:  Calling Mr Jones to Office 3.

I need to get the values 'Mr Jones & Office 3. I can include limiter to identiy the positons

Andy
ASKER CERTIFIED SOLUTION
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
another option is to use RegEx
if you decide to use RegEx, try this pattern: "\{.*?\}"
try this,

 Dim spl As String() = Split(ConfigurationManager.AppSettings("Message"), " to ")
        Dim client As String = Replace(spl(0), "Calling", "")
        Dim room As String = spl(1)

        Response.Write("<br>" & client & " & " & room)

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks Guys