字符串中的引号

发布于 2024-11-26 20:51:48 字数 363 浏览 5 评论 0原文

我有一些带有变量的字符串,例如

string path = @"C:\one\filename.exe" + arguments

arguments: "-s -c -d > "somedirectory\some file.txt""

我在将输出重定向到 "somedirectory\some file" 时遇到问题 如果我输入 "\""char.ToString('"') 它总是解释为 \"...而不是单独 "

我应该如何将这个 " 字符放入参数中?

I have some string with variable, e.g.

string path = @"C:\one\filename.exe" + arguments

arguments: "-s -c -d > "somedirectory\some file.txt""

I've problem with redirection output to "somedirectory\some file"
If I put "\"" or char.ToString('"') it always interprets as \"...not alone "

How should I put this " character into arguments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

ゃ人海孤独症 2024-12-03 20:51:48

您需要使用 \"

调试器将其显示为 \",因为它显示有效的字符串文字。
但是,字符串中的实际值是 "。(您可以在文本可视化工具中看到这一点)

在逐字字符串文字 (@"...") 中,您可以需要使用 "" 代替。

You need to use \".

The debugger shows it as \", since it shows valid string literals.
However, the actual value in the string is ". (You can see this in the Text Visualizer)

In a verbatim string literal (@"..."), you need to use "" instead.

梦醒灬来后我 2024-12-03 20:51:48
var arguments =  @"-s -c -d > ""somedirectory\some file.txt""";

或者

var arguments = "-s -c -d > \"somedirectory\\some file.txt\"";
var arguments =  @"-s -c -d > ""somedirectory\some file.txt""";

or

var arguments = "-s -c -d > \"somedirectory\\some file.txt\"";
只为一人 2024-12-03 20:51:48
string args = @"-s -c -d > ""somedirectory\some file.txt"""

尝试一下。

有关详细信息,http://msdn.microsoft .com/en-us/library/aa691090%28v=vs.71%29.aspx

string args = @"-s -c -d > ""somedirectory\some file.txt"""

try that.

for more information, http://msdn.microsoft.com/en-us/library/aa691090%28v=vs.71%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文