gpt4 book ai didi

c# - 在 web.config 中转义引号和 @

转载 作者:太空宇宙 更新时间:2023-11-03 21:55:33 24 4
gpt4 key购买 nike

您好,我正在尝试从 web.config 中获取以下内容

@"酋长\阿达玛";

并将按如下方式使用它:

var queuePath = @"Chief\adama";

目前我有:

 <add key="AdamaPath" value="@Chief\adama" />

实际上只有主要部分会发生变化,我已经尝试了以下方法:

网络配置:

<add key="AdamaPath" value="Chief" />

.cs:

var machine = ConfigurationManager.AppSettings["AdamaPath"];
var queuePath = "@" + "\"" + machine + "\adama" + "\"";

但我得到:"@\"酋长\adama\""

我也试过:

 <add key="AdamaPath" value="@ &quot; Chief\adama &quot;" />

这也得到:

"@\"酋长\adama\""

谁能告诉我如何去掉多余的 "和\谢谢!

最佳答案

以下可能是您所需要的:

<add key="AdamaPath" value="Chief" />

var machine = ConfigurationManager.AppSettings["AdamaPath"];
var queuePath = machine + "\\adama";

上面会产生一个包含Chief\adama的字符串,这似乎是你需要的。

@ 表示逐字字符串文字(当位于字符串文字之前时)- 您正在构造包含 this 的字符串,它不能工作,因为它是 C#特征和需要先于字符串文字

关于c# - 在 web.config 中转义引号和 @,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12474728/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com