<分区>
<分区>
我在打开当前 HTML 文件并使用 StringBuilder 替换我需要的内容时遇到 HTML 问题...下面是我用来执行此操作的代码位...
'Lets replace the grid information!'
Dim sb As New StringBuilder()
sb.AppendLine(" <table>")
sb.AppendLine("<tr>")
' sb.AppendLine("<th>")
For Each column As DataGridViewColumn In DataGridView1.Columns
sb.AppendLine(" <th>" + column.HeaderText + "</th>")
Next
' sb.AppendLine("</th>")
sb.AppendLine(" </tr>")
sb.AppendLine("</table")
HTML.Replace("%TABLE%", sb.ToString)
到目前为止一切正常,我遇到的唯一问题是去掉客户名称字段中的“<”……我知道这是因为替换;它在那里添加了一个额外的。但是如果我把它从附加行中取出,我的网格就会乱七八糟……这是这个的屏幕截图……
这是我正在抓取的 HTML 文件的源代码,然后替换了我需要的内容...
<!doctype html>
<html>
<head>
<title>Invoice %Invoice%</title>
<link rel="stylesheet" href=%STYLE%>
<style type="text/css">
@import url("style.css");
</style>
</head>
<body>
<header>
<h1>Invoice %Invoice%</h1>
<address>
<p>%Business%</p>
</address>
<img src="file:///%Image%" alt="" align="right">
</header>
<article>
<h1> </h1>
<h1> </h1>
<h1> </h1>
<h1>Recipient</h1>
<address>
<p>%Company%</p>
<p>%Contact%</p>
<p>%Address%</p>
</address>
<table class="meta">
<tr>
<th><span>Invoice #</span></th>
<td><span>%Invoice%</span></td>
</tr>
<tr>
<th><span>Date</span></th>
<td><span>%Date%</span></td>
</tr>
<tr>
<th><span>Amount Paid</span></th>
<td><span id="prefix">$</span><span>0.00</span></td>
</tr>
<tr>
<th><span>Amount Due</span></th>
<td><span id="prefix">$</span><span>600.00</span></td>
</tr>
</table>
<%TABLE%> THIS IS WHERE I SEND THE TABLE TO!
</article>
<aside>
<h1> </h1>
<h1> </h1>
<h1><span>Additional Notes</span></h1>
<div contenteditable>
<p align ='center'>A finance charge of 1.5% will be made on unpaid balances after 30 days.</p>
</div>
</aside>
</body>
</html>
谢谢!
最佳答案
假设 HTML 是一个字符串,替换函数返回一个字符串结果,所以您需要:
HTML = HTML.Replace("%TABLE%", sb.ToString)
根据 pickypg 的回答你可能真的需要:
HTML = HTML.Replace("<%TABLE%>", sb.ToString)
关于html - 无法使用替换从 HTML 中删除不需要的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14411420/