Reputation: 14331
Whats the best way to make the following HTML text block a hardcoded string object in c#? I need it for a test can't use the @ operator since it just stops at the first ". Any ideas?
====================================================
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=utf-8">
<TITLE>Example Web Page</TITLE>
</HEAD>
<body>
<p>You have reached this web page by typing "example.com",
"example.net","example.org"
or "example.edu" into your web browser.</p>
<p>These domain names are reserved for use in documentation and are not available
for registration. See <a href="http://www.rfc-editor.org/rfc/rfc2606.txt">RFC
2606</a>, Section 3.</p>
</BODY>
</HTML>
Upvotes: 0
Views: 123
Reputation: 14161
Probably this link might answer your question:
Storing HTML tags in a string variable.
Upvotes: 0
Reputation: 4841
If you don't want to embed it like Jon Skeet's answer, you'll have to change all occurences of "
to ""
.
Upvotes: 1
Reputation: 7600
You can use @ but you have to escape any " as "" (double)
There is no other way as far as I have found.
First lines would then be
@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">
<HTML>
Upvotes: 6
Reputation: 1500525
I would suggest you put it in a text file that you then embed into the assembly. That way you can edit it with syntax highlighting etc, and it won't clutter up your code.
Use Assembly.GetManifestResourceStream
to load it again at execution time. If you do this a fair amount, you might want to write helper methods to do it more easily.
Upvotes: 5