尝试将<hr />标记放入stringBuilderObject.Append()VB.net时发生对象引用错误

时间:2018-10-08 10:24:17

标签: vb.net stringbuilder

我的主要目的是使用VB.net在pdf中用蓝色标记某些单词。代码如下所示:

strSignHTML.Append("<TD class=""TBLDATA"" width=""25%"" align=left><br /><br>")
strSignHTML.Append("<hr color=""midnightblue"">")
strSignHTML.Append("</TD>")
strSignHTML.Append("<td width=50%>&nbsp;</td>")
strSignHTML.Append("<td class=""TBLDATA"" width=""25%"" align=left> <br>")
strSignHTML.Append("<hr color=""midnightblue"">")
strSignHTML.Append("</td>")
strSignHTML.Append("</tr>")
strSignHTML.Append("<tr>")
strSignHTML.Append("<td class=""TBLDATA"">")
strSignHTML.Append("<font color=""midnightblue""><b>Signature</b></font>")
strSignHTML.Append("</td>")
strSignHTML.Append("<td width=50%>&nbsp;</td>")
strSignHTML.Append("<td class=""TBLDATA"">")
strSignHTML.Append("<font color=""midnightblue""><b>Date</b></font>")
strSignHTML.Append("</td>")
strSignHTML.Append("</tr>")
strSignHTML.Append("<tr>")

1 个答案:

答案 0 :(得分:0)

导入库后

Imports System.Text

实际上将strSignHTML设置为StringBuilder很好

    Dim strSignHTML As New StringBuilder
    strSignHTML.Append("<TD class=""TBLDATA"" width=""25%"" align=left><br /><br>")
    strSignHTML.Append("<hr color=""midnightblue"">")
    strSignHTML.Append("</TD>")
    strSignHTML.Append("<td width=50%>&nbsp;</td>")
    strSignHTML.Append("<td class=""TBLDATA"" width=""25%"" align=left> <br>")
    strSignHTML.Append("<hr color=""midnightblue"">")
    strSignHTML.Append("</td>")
    strSignHTML.Append("</tr>")
    strSignHTML.Append("<tr>")
    strSignHTML.Append("<td class=""TBLDATA"">")
    strSignHTML.Append("<font color=""midnightblue""><b>Signature</b></font>")
    strSignHTML.Append("</td>")
    strSignHTML.Append("<td width=50%>&nbsp;</td>")
    strSignHTML.Append("<td class=""TBLDATA"">")
    strSignHTML.Append("<font color=""midnightblue""><b>Date</b></font>")
    strSignHTML.Append("</td>")
    strSignHTML.Append("</tr>")
    strSignHTML.Append("<tr>")

    Dim myString As String = strSignHTML.ToString

即使如此,我还是更愿意使用CDATA

Dim myString As String = <![CDATA[
                <TD class="TBLDATA" width="25%" align=left><br /><br>
                <hr color="midnightblue">
                </TD>
                <td width=50%>&nbsp;</td>
                <td class="TBLDATA" width="25%" align=left> <br>
                <hr color="midnightblue">
                </td>
                </tr>
                <tr>
                <td class="TBLDATA">
                <font color = "midnightblue"><b>Signature</b></font>
                </td>
                <td width = 50% >& nbsp;</td>
                <td class="TBLDATA">
                <font color = "midnightblue"><b>Date</b></font>
                </td>
                </tr>
                <tr>]]>.Value