string str1="xxx";
string str2=@"sss" + str1 + "ddd";
Console.WriteLine(str2);
The above code gives:
sssxxxddd
But what I want is:
sss" + str1 + "ddd
How to do that?
string str1 = "xxx";
string str2 = @"sss"" + str1 + ""ddd";
Console.WriteLine(str2);
string str3 = "xxx";
string str4 = "sss\" + str1 + \"ddd";
Console.WriteLine(str4);
Console.ReadKey();
string str1="xxx";
string str2=@"sss""" + str1 + @"""ddd";
Console.WriteLine(str2);
or
string str1="xxx";
string str2="sss\"" + str1 + "\"ddd";
Console.WriteLine(str2);
This will give you an answer like: sss"xxx"ddd. If you want an answer like sss" + str1 + "ddd then you replace the second line with this: string str2=@"sss"" + str1 + ""ddd";
You can escape the quotes by preceding them with a backslash (
\
).For strings prefixed with the
@
character, quotes are escaped by placing two together (i.e.,string str2 = "sss"" + str1 + ""ddd"
).