.net 如何在 app.config 中使用双引号

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3979297/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 14:49:42  来源:igfitidea点击:

How to use double quotes in app.config

.net

提问by Captain Comic

I need to put double quotes in configuration property Property1

我需要在配置属性 Property1 中加上双引号

 <Seection Name Propety1="" .../>

回答by Andrew Barber

I believe the proper way to encode quotes in XML is via &quot;

我相信在 XML 中编码引号的正确方法是通过 &quot;

See this answer: How do I escape double quotes in attributes in an XML String in T-SQL?

请参阅此答案: 如何在 T-SQL 中的 XML 字符串中对属性中的双引号进行转义?

The same would go for any other 'special' characters you wish to include as data. Essentially, you should use the same encoding you would use in HTML attributes.

您希望作为数据包含的任何其他“特殊”字符也是如此。本质上,您应该使用在 HTML 属性中使用的相同编码。

回答by Andy Rose

You could html encodethe value when you add it to the configuration file. This should ensure any special character will be handled correctly in the xml and be returned as expected.

将值添加到配置文件时,您可以进行 html 编码。这应该确保在 xml 中正确处理任何特殊字符并按预期返回。