In my application there is a requirement to remove special characters from a string. I am able to achieve this by reading a string of special chars from config appsettinf key-value pair.
EX :
<appSettings>
<add key="ExcludeSpecialChars" value ="%'^"/>
</appSettings>
I am facing problem when I include & in the value ex :
key="ExcludeSpecialChars" value ="&%'^"
The application fails to build and shows an error "cannot parse the entity".
Is there any workaround so that I can include &
in the special chars string?
Since .NET .config files are XML, use the entity &
to represent an ampersand:
<appSettings>
<add key="ExcludeSpecialChars" value ="&%'^"/>
</appSettings>
Some characters have a special meaning in XML.
If you place a character like "&" inside an XML element, it will generate an error because the parser interprets it as the start of a new element.
you can use &
there are 5 predefined entity references in XML
< < less than
> > greater than
& & ampersand
' ' apostrophe
" " quotation mark
ref :http://www.w3schools.com/xml/xml_syntax.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With