html - 无法使用替换从 HTML 中删除不需要的字符

标签 html css vb.net replace stringbuilder

<分区>

我在打开当前 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)

到目前为止一切正常,我遇到的唯一问题是去掉客户名称字段中的“<”……我知道这是因为替换;它在那里添加了一个额外的。但是如果我把它从附加行中取出,我的网格就会乱七八糟……这是这个的屏幕截图……

ERROR IM HAVING

这是我正在抓取的 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>&nbsp;</h1>
        <h1>&nbsp;</h1>
        <h1>&nbsp;</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>&nbsp;</h1>
        <h1>&nbsp;</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/

上一篇:CSS Transition 从左到右有效,从右到左无效

下一篇:jquery - 默认链接颜色保持事件状态,直到鼠标单击另一个链接

相关文章:

javascript - 没有获得正确的图像宽度

html - 侧面固定菜单重叠在 div 下方

javascript - 如何用 jQuery 替换 innerHTML?

jquery - 根据该 anchor jquery中的特定文本向 anchor 添加一个类

vb.net - 使用VB.NET查找当前登录用户的用户名

sql-server - 如果数据为 null,XmlNode.InnerText 将中断

.net - 以编程方式隐藏 PropertyGrid 中的字段

html - 无溢出的 float 多级顶部导航

html - 自动、0 和无 z-index 之间的区别?

javascript - 使用 Javascript 向现有 CSS 元素添加像素