简体   繁体   English

如何在C#中使用定界符?

[英]How to use delimiter in C#?

start.FileName = @"C:/Program Files/xyz/asd -config \"C:/Users/xyz/qwe\""

When I'm using the above code its giving the error at the 当我使用上面的代码时,在

closing delimiter "\\" unexpected character . closing delimiter “ \\” unexpected character

The @ symbol in front of the string specifier instructs the C# compiler to use a different escape mechanism for the string, effectively ignoring all of the standard escape sequences and rendering them as text. 字符串说明符前面的@符号指示C#编译器对字符串使用不同的转义机制,从而有效地忽略所有标准转义序列并将其呈现为文本。 The only escape sequence that is used in the alternate form of string specifier is the "" escape sequence which inserts a single " character in the output. 字符串说明符的替代形式中使用的唯一转义序列是""转义序列,该转义序列在输出中插入单个"字符。

Try your string as: 尝试使用以下字符串:

start.FileName = @"C:/Program Files/xyz/asd -config ""C:/Users/xyz/qwe""";

Or: 要么:

start.FileName = "C:/Program Files/xyz/asd -config \"C:/Users/xyz/qwe\"";

Either one works. 任一个作品。 Or, since you're targeting a windows platform: 或者,由于您的目标是Windows平台:

start.FileName = @"C:\Program Files\xyz\asd -config ""C:\Users\xyz\qwe""";

http://msdn.microsoft.com/en-us/library/362314fe.aspx http://msdn.microsoft.com/en-us/library/362314fe.aspx

The advantage of verbatim strings is that escape sequences are not processed, which makes it easy to write, for example, a fully qualified file name: C# 逐字字符串的优点是不处理转义序列,这使编写例如完整的文件名C#变得容易。

@"c:\Docs\Source\a.txt"  // rather than "c:\\Docs\\Source\\a.txt"

To include a double quotation mark in an @-quoted string, double it: 要在@引号字符串中包含双引号,请将其加倍:

@"""Ahoy!"" cried the captain." // "Ahoy!" cried the captain.
string line = "C:/Program Files/xyz/asd -config \"C:/Users/xyz/qwe**\"";

Console.WriteLine(line);

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

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