首页 > 解决方案 > 向 C# 中变量内的字符串添加双引号时遇到问题?

问题描述

我正在尝试传递一个filepathtoxcopy command将文件夹从一个位置复制到另一个位置(CodedUI using C#)。虽然做同样的问题是,我试图在路径周围添加双引号,但它没有采用正确的路径格式。

Code: 
string Path = "Some path to folder location";

// Tried all these solutions

Path = '\"' + Path + '\"';
Path = '\"' + Path + '\"';
Path = string.Format("\"{0}\"", Path );

预期:""Some path to folder location"" 实际:"\"Some path to folder location"\"

请帮忙。

标签: c#coded-ui-testsxcopy

解决方案


也许您应该尝试逐字字符串,例如@"the\path\to\another\location".
这是编写路径的最佳方式,无需与转义码作斗争。

编辑:
您可以在逐字字符串中使用双引号:
@"""the\path\to\another\location"""


推荐阅读