Friday, March 16, 2012

Parameterized String

Hi-

I did come accorss an example in the past, but can't find it now.

Here is what I am trying to do.
I want to setup a string value in web.config, which will hold a couple of lines of HTML.

1) How can I put HTML tags, such as <p> in the value of a key?
2) How to have a dynamic parameter in the string, and how to replace that parameter with actual value?

I am doing this, is it correct?
<add key="someKey" value="Hello#1,<p>This is test message."/
Basically want to have something like this eventually.
----------
Hello Mr.Foo,

This is test message.
----------

How do I replace #1 with Mr.Foo? There could be more than 1 parameter, and will be given incremental numbers, i.e. #1, #2, etc.

Your help is much appreciated.

Regards. :-)I'm not sure you can actually do this in the Web.config without parsing the incoming value of the string.
Hi,

Try below code :
web.config
==========


<configuration>
<appSettings>
<add key="someKey" value="Hello#1,<p>This is test message."/>
</appSettings>
</configuration>

Code behind
==========


Dim SomeString As String = ConfigurationSettings.AppSettings("someKey")
Dim NewString As String = SomeString.Replace("#1", "Mr.Foo")

HTH
Hi Shaji-

Thanks for the prompt reply.

Though that is one of the option, I could also use Regex, etc.
But I am looking for something different than what you have posted.

I was hoping to see something like this for this example, if it's possible to do so?:

Dim strString As String = New String(ConfigurationSettings.AppSettings("someKey"), "Mr. Foo")

Thanks :-)
Hi,

Try :

 Dim SomeString As String = ConfigurationSettings.AppSettings("someKey").Replace("#1", "Mr.Foo")
Response.Write(SomeString)

HTH

0 comments:

Post a Comment