AppConfig key value pair

My application has a requirement to remove special characters from a string. I can achieve this by reading the string of special characters from the appsettinf key pair.

EX:

<appSettings> <add key="ExcludeSpecialChars" value ="%'^"/> </appSettings> 

I ran into a problem when I turn on ex too:

 key="ExcludeSpecialChars" value ="&%'^" 

The application does not create and shows the error "cannot parse the object."

Is there a workaround to include & in the string of special characters?

+6
source share
2 answers

Since the .NET.config files are XML, use entity &amp; to represent the ampersand:

 <appSettings> <add key="ExcludeSpecialChars" value ="&amp;%'^"/> </appSettings> 
+6
source

Some characters have special meanings in XML.

If you put a character like "&" inside an XML element, it will generate an error because the parser interprets it as the beginning of a new element.

you can use &amp; There are 5 predefined object references in XML

 &lt; < less than &gt; > greater than &amp; & ampersand &apos; ' apostrophe &quot; " quotation mark 

ref: http://www.w3schools.com/xml/xml_syntax.asp

+5
source

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


All Articles