【问题标题】:How do I create a string from a block of text that contains the " character如何从包含 " 字符的文本块创建字符串
【发布时间】:2011-03-14 11:23:30
【问题描述】:

我有一段 html 代码,其中包含一些表单操作内容,其中“出现很多”。

有没有办法可以将整个块变成一个字符串?

public string methodName()
{
     return @ " text goes here..  blah blah  <p> a bit of html stuff</p>
<form action="www...." method="post">
<input type="hidden" name="cmd" 

我得到了很多愤怒的红色下划线。

【问题讨论】:

  • 你能说得更具体一点吗?也许提供一些您拥有的 HTML 代码示例并解释预期结果?

标签: c# html string


【解决方案1】:
var html = @"<html>
<body>
    <span id=""name""> somethnig more</span>
</body>
</html>";

将@ 放在字符串之前意味着不应解析内容(\n 和其他控制字符不起作用)。也意味着字符串可以跨越多行,里面有“”,只要写“”(只会显示一个)。

【讨论】:

  • 顺便说一下,这被称为逐字字符串文字。
猜你喜欢
  • 2021-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-29
  • 2011-02-17
  • 2021-03-04
  • 1970-01-01
  • 2014-08-01
相关资源
最近更新 更多