I need to print
a
"b"
c
with the vebatim string, I posed another question about multiple line code template here.
I tried with verbatim string as follows :
using System;
class DoFile {
static void Main(string[] args) {
string templateString = @"
{0}
\\"{1}\\"
{2}
";
Console.WriteLine(templateString, "a", "b", "c");
}
}
But, I got this error.
t.cs(8,11): error CS1525: Unexpected symbol `{'
t.cs(9,0): error CS1010: Newline in constant
t.cs(10,0): error CS1010: Newline in constant
\"{1}\"
doesn't work neither.
What's wrong?
In C#, a verbatim string is created using a special symbol @. @ is known as a verbatim identifier. If a string contains @ as a prefix followed by double quotes, then compiler identifies that string as a verbatim string and compile that string.
In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals.
You can use " \\ " instead of " \ " as well as '@' sign in the beginning.
From the C# documentation it states that the @ symbol is an Identifier. The prefix “@” enables the use of keywords as identifiers, which is useful when interfacing with other programming languages.
Try this ( "" instead of " to escape )
string templateString = @"
{0}
""{1}""
{2}
";
From C# specification: http://msdn.microsoft.com/en-us/library/Aa691090
quote-escape-sequence: ""
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With