简体   繁体   English

C#双引号参数

[英]C# double quote argument

In the app.config file, I have:在 app.config 文件中,我有:

add key="DataFileLocation" value="E:\Program Files\Microsoft SQL Server\MSSQL12.MSSQLSERVER\MSSQL\DATA\"/>

In the code I have:在代码中我有:

Process P2 = new Process();
P2.StartInfo.FileName = "restore.bat";
P2.StartInfo.Arguments = + "\"" + DataFileLocation.ToString() + "\"";
P2.StartInfo.UseShellExecute = false;
P2.StartInfo.RedirectStandardOutput = true;
P2.StartInfo.CreateNoWindow = true;
P2.Start();

The output to 'restore.bat' is: “restore.bat”的输出是:

-v dataloc=\"E:\\Program Files\\Microsoft SQL Server\\MSSQL12.MSSQLSERVER\\MSSQL\\DATA\\\"

As you can see, there's an extra "\\" at the beginning which is breaking the bat/sql statement...如您所见,开头有一个额外的“\\”,它破坏了 bat/sql 语句......

Andrew安德鲁

In your case it seems like you are already adding a extra \\ , so is the output according to your logic.在您的情况下,您似乎已经添加了一个额外的\\ ,根据您的逻辑输出也是如此。

The best way to combine path is that you should use the Path.Combine method provided by static Path class, it takes care of all the extra \\组合路径的最佳方法是您应该使用静态Path类提供的Path.Combine方法,它会处理所有额外的\\

Try this尝试这个

var finalPath = Path.Combine(DataFileLocation.ToString(), "what_ever_path_you_want_to_combine");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM