Is it possible to have a multiline C# string that contains html?
The following works fine:
string output = @"Qiuck
brown
fox
jumps
over
the
lazy
log";
But this does not work:
string output = @"&开发者_高级运维lt;object>
<node>
<param value=\"test\" />
</node>
</object>
";
However this similar example does work, I have just taken out the attribute on param:
string output = @"<object>
<node>
<param />
</node>
</object>
";
Any suggestions on the best way to package html into a string variable? If it is not possible I am assuming the next best method is just to read from a file? Any other ideas?
The problem with example 2 seems to be the escaped quotes.
Use double quotes instead of escaping them.
string output = @"<object>
<node>
<param value=""test"" />
</node>
</object>
";
Use ""
instead of \"
. It will still output "
. When you're doing literal strings, the escape character isn't processed:
string output = @"<object>
<node>
<param value=""test"" />
</node>
</object>
";
Use single quotes in the param.
精彩评论