本文介绍了我需要逃脱反斜杠在配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个配置文件,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";
这篇关于我需要逃脱反斜杠在配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!