【问题标题】:how to get the text content of html [duplicate]如何获取html的文本内容[重复]
【发布时间】:2012-11-21 20:34:02
【问题描述】:

可能重复:
How can I strip HTML tags from a string in ASP.NET?

asp.net中如何获取html的文本内容?

我在 asp.net 中编写了以下代码,但它给了我 html 而不是文本?

代码在这里:

Function GetData(ByVal dta As String)

        Dim comp As New Literal
        comp.Text = dta
            Return comp.Text
End Function

例如:

输入:<span><p> this is html </p></span>

输出应该是:这是html

【问题讨论】:

  • 你要的是正在执行的asp页面的内容还是外部html页面的内容?
  • 这个真的不清楚。你给这个方法什么输入,你期望什么输出,你得到什么?
  • 不要认为comp 做了很多事情,你所做的只是复制字符串,然后返回结果,如此有效地返回dta。所以这基本上只是一个恒等函数。你想做什么,什么不起作用?
  • 问题很明确,我需要来自 html 的文本内容,例如

    hi all

    我需要返回 hi all
  • 好的,我已经编辑了问题

标签: asp.net .net vb.net web


【解决方案1】:

试试这个

Function GetData(ByVal dta As String)

        Return Regex.Replace(dta, "<[^>]*(>|$)", String.Empty)
    End Function

【讨论】:

    猜你喜欢
    • 2011-06-24
    • 2020-11-05
    • 1970-01-01
    • 2022-11-23
    • 1970-01-01
    • 2021-03-04
    • 2018-11-10
    • 2014-09-19
    • 1970-01-01
    相关资源
    最近更新 更多