How to pass string literal from settings file in C #

I want to create a configuration parameter to pass a string to my application. The line is based on some text from a web page, so I must allow it to be changed from the configuration file.

The line I want to pass is

a)

Forecast Summary:</b> <span class="phrase"> 

And the string literal format, which works when I use it to search on a page,

b)

 string myString = "Forecast Summary:</b> \n <span class=\"phrase\">"; 

the problem is that the transmitted string (by inserting the text in (a) above in the application settings screen) passes in the format

with)

 "Forecast Summary:</b> \r\n <span class=\"phrase\">" 

(which has a carriage return inserted)

Is there a way to enter a string in App.Config as an "exact" string literal

+4
source share
2 answers

You need to use CDATA or Escape codes.

 <myxml> <record> <![CDATA[ Line 1 <br /> Line 2 <br /> Line 3 <br /> ]]> </record> </myxml> 

see here for more info on XML Escaping

for more information see: here and here

+1
source

I first solved this by injecting XML encoded characters directly into App.Config.

 <setting name="DataExtractFrom" serializeAs="String"> <value>Forecast Summary:&lt;/b&gt; &#10; &lt;span class="phrase"&gt;</value> </setting> 

(I used to insert it in the settings screen for a project, which should add an extra carriage return)

then

As suggested above, it works if I edit the App.Config file using the CDATA format.

 <setting name="DataExtractFrom" serializeAs="String"> <value><![CDATA[Forecast Summary:</b> \n <span class=\"phrase\">]]></value> </setting> 

It looks cleaner in the configuration file, so I ended up using this format.

0
source

Source: https://habr.com/ru/post/1442227/


All Articles