【问题标题】:to Identify the Html tag and replace its element in vb.net识别 Html 标签并在 vb.net 中替换其元素
【发布时间】:2015-05-05 11:12:52
【问题描述】:

我在数据库中有如下数据: 例如

<p><font style="BACKGROUND-COLOR: gold" size="+2" face="Arial Black"><strong>test</strong><u> test1</u> </font></p> 

我需要从我的代码中检索数据并删除 html 标签并应用相同的元素效果。如果有像 ,,, 这样的标签 所有这些都应以提供的文本为准。

所以,在上面的例子中,输出将是 likr 测试(粗体,字体样式) test1(带下划线)。 测试测试1

请建议在 vb.net 中实现这一点

【问题讨论】:

标签: html css asp.net vb.net


【解决方案1】:

1) Example of HTML string parsing with C#.NET

2) http://htmlagilitypack.codeplex.com/ - 这是常用的服务器端解析器。我会推荐这个。

3) 操作 html 对象会更容易。否则,您可以尝试在字符串 REGEX 替换的帮助下进行解析,这将是一个非常繁琐且复杂的工作。

【讨论】:

    【解决方案2】:

    VB.NET 为此得到了asp:Literal

    <asp:Literal ID="literal" runat="server" />
    

    在这样的代码中使用它。

    Dim code As String = "<p><font style=""BACKGROUND-COLOR: gold"" size=""+2"" face=""Arial Black""><strong>test</strong><u> test1</u> </font></p>"
    literal.Text = code
    

    【讨论】:

      猜你喜欢
      • 2015-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多