How can I add " character to a multi line string declaration in C#?
C#StringEscapingC# Problem Overview
If I write something like this:
string s = @"...."......";
it doesn't work.
If I try this:
string s = @"...\".....";
it doesn't work either.
How can I add a " character to a multi line string declaration in C#?
C# Solutions
Solution 1 - C#
Try this:
string s = @"..."".....";
Solution 2 - C#
The double character usage also works with the characters { and } when you're using string.Format
and you want to include a literal instance of either rather than indicate a parameter argument, for example:
string jsString = string.Format(
"var jsonUrls = {{firstUrl: '{0}', secondUrl: '{1}'}};",
firstUrl,
secondUrl
);
Solution 3 - C#
string s = "...\".....";
should work
the @ disables escapes so if you want to use " then no @ symbol
Personally i think you should go with
string s = string.format("{0}\"{1},"something","something else");
it makes it easier in the long run