簡體   English   中英

在C#中使用此字符串值的最佳方法是什么?

[英]What is the best way of using this string value in c#?

在c#中使以下HTML文本塊成為硬編碼字符串對象的最佳方法是什么? 我需要它來進行測試,因為它只是在第一個“。”處停止,所以不能使用@運算符。

================================================== ==

<!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 &quot;example.com&quot;,

&quot;example.net&quot;,&quot;example.org&quot

  or &quot;example.edu&quot; 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>

您可以使用@,但是必須轉義任何“ as”(雙精度)

據我所知,沒有其他方法。

然后第一行是

@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"">

<HTML>

我建議您將其放在一個文本文件中,然后嵌入到程序集中。 這樣,您可以使用語法高亮顯示等對其進行編輯,並且不會使您的代碼混亂。

使用Assembly.GetManifestResourceStream在執行時再次加載它。 如果您這樣做相當多,則可能需要編寫幫助程序方法來更輕松地完成此操作。

如果您不想像Jon Skeet的回答那樣嵌入它,則必須將所有出現的"更改為""

此鏈接可能會回答您的問題:

將HTML標簽存儲在字符串變量中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM