c# - 向 C# 中变量内的字符串添加双引号时遇到问题?
问题描述
我正在尝试传递一个filepath
toxcopy
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"\"
请帮忙。
解决方案
也许您应该尝试逐字字符串,例如@"the\path\to\another\location"
.
这是编写路径的最佳方式,无需与转义码作斗争。
编辑:
您可以在逐字字符串中使用双引号:
@"""the\path\to\another\location"""
推荐阅读
- dapr - 如何在 Dapr Pub/Sub 组件中以声明方式订阅多个主题?
- javascript - React UserContext 对象给出未定义的值?(无法映射)
- javascript - 我应该如何使用 react-quill 将 HTML 内容存储到数据库
- c++ - 将每个枚举成员关联到一个类并从该类获取通用信息
- r - 从 R Dataframe 中提取隐藏信息
- python - 向所有四个子图添加 y-ticks,但仅在两个子图中保留 x-ticks
- reactjs - 为什么这些功能不在主要功能组件中?
- ruby-on-rails - ActiveRecord where 方法返回空数组
- python - 根据不同的索引在 pandas 中添加一个新的条件列
- css - 每次页面滚动时如何触发动画?