我需要逃脱反斜杠在配置文件?斜杠、配置文件

2023-09-03 00:47:22 作者:星月山河都做贺礼

我有一个配置文件,myapp.exe.config。 在该文件中我有一个完整路径文件名作为值的属性。

I have a config file, myapp.exe.config. In the file I have an attribute with a fullpath filename as the value.

<add key="InfoFile" value="c:\temp\info.txt" />

这似乎工作,如果我使用的是单或双反斜线。即,

It seems to work if I use a single or double backslash. That is,

<add key="InfoFile" value="c:\\temp\\info.txt" />

作品也。什么是做到这一点的正确方法?

works also. What is the correct way to do this?

推荐答案

您不必说。属性值中的任何事情都是字符数据。

You don't need that. Anything within an attribute value is character data.

既然你读这些值与C#中,他们会得到转义字符它在实际的C#code以同样的方式。

Since you're reading these values with C#, they'll get escaped characters the same way it does in actual C# code.

无论如何,请记住C#有@运营商,这意味着你不需要逃脱反斜杠:

Anyway, remember C# has @ operator, meaning you don't need to escape backslashes:

string somePath = @"C:\blah\blih\bluh.txt";
 
精彩推荐
图片推荐