Avatar of Andy Green
Andy Green
Flag 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
ASP.NETVisual Basic.NET

Avatar of undefined
Last Comment
Andy Green

8/22/2022 - Mon
Rajar Ahmed

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


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

Open in new window

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
YZlat

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
YZlat

another option is to use RegEx
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
YZlat

if you decide to use RegEx, try this pattern: "\{.*?\}"
Rajar Ahmed

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
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Andy Green

ASKER
Thanks Guys
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.