简体   繁体   English

查找不包含html标记的字符串

[英]Finding the string excluding the html tags

Can I get the string without the html tags which will be displayed on the webbrowser control ? 我可以获取不带html标记的字符串,该标记将显示在webbrowser控件上吗?

Like I have String str = "html hello html" then I want to find the string like hello. 就像我有String str =“ html hello html”一样,然后我想找到像hello这样的字符串。

How can I do that? 我怎样才能做到这一点?

Regular expressions aren't ideal for HTML. 正则表达式不是HTML的理想选择。 Regular expressions are for regular text, not HTML. 正则表达式适用于常规文本,而不适用于HTML。

Use an HTML parser library such as the free, open source HTML Agility Pack . 使用HTML解析器库,例如免费的开源HTML Agility Pack It comes bundled with an HTML-to-Text converter sample . 它与HTML到文本转换器样本捆绑在一起。

You can use a regular expression to strip the html tags, like: 您可以使用正则表达式去除html标签,例如:

string html = "Your html string";
string x = Regex.Replace(html,@"<(.|\n)*?>", string.Empty);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM