Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在C中正确构造html字符串#_C#_Html - Fatal编程技术网

C# 如何在C中正确构造html字符串#

C# 如何在C中正确构造html字符串#,c#,html,C#,Html,我需要创建此html字符串: <table cellspacing="2" style="width:100%"> <tr height="30" nowrap="NOWRAP" width="200" bgcolor="#f4f4f4"> <th>Product</th> <th>Category</th> <th>Price</th> </

我需要创建此html字符串:

<table cellspacing="2" style="width:100%">
    <tr height="30" nowrap="NOWRAP" width="200" bgcolor="#f4f4f4">
      <th>Product</th>
      <th>Category</th> 
      <th>Price</th>
   </tr>
   <tr>
      <td>Replace</td>
      <td>Replace</td>
      <td>Replace</td>
  </tr>
</table>

产品
类别
价格
代替
代替
代替

我有一份我打算替换的物品清单。我试图使用
StringBuilder
,但它不起作用

您可以将
@
用于逐字记录字符串,并将
标记加倍以转义它们。您还可以将
字符串.Format
{}一起使用
占位符用于插入值,尽管它们不是html编码的,因此如果您有类似
的字符,可以使用
@
作为逐字字符串,并将
标记加倍以转义它们。您还可以使用
string.Format
{}
占位符来插入值,尽管它们不是html编码的。因此,如果您有
这样的字符,“它不工作”是什么意思?你的应用程序崩溃了吗?你有没有得到一个意想不到的结果?到底发生了什么?此外,您还需要提供到目前为止的代码,您可以用许多不同的方式替换/构建字符串,在您阐明如何执行此操作之前,没有人可以回答您的问题。当我尝试创建类似于
cellspacting=“2”
的东西时,它不起作用。“td”必须被列表中的项目所取代。也许值得一看“它不起作用”是什么意思?你的应用程序崩溃了吗?你有没有得到一个意想不到的结果?到底发生了什么?此外,您还需要提供到目前为止的代码,您可以用许多不同的方式替换/构建字符串,在您阐明如何执行此操作之前,没有人可以回答您的问题。当我尝试创建类似于
cellspacting=“2”
的东西时,它不起作用。“td”必须被列表中的项目所取代。也许值得一看感谢,这正是我所需要的!谢谢,这正是我需要的!
var html = string.Format(
@"<table cellspacing=""2"" style=""width:100%"">
    <tr height=""30"" nowrap=""NOWRAP"" width=""200"" bgcolor=""#f4f4f4"">
      <th>Product</th>
      <th>Category</th> 
      <th>Price</th>
   </tr>
   <tr>
      <td>{0}</td>
      <td>{1}</td>
      <td>{2}</td>
  </tr>
</table>", listItem[0], listItem[1], listItem[2]);