从 vb.net 中的字符串中删除 img 标签 [英] Remove img tag from string in vb.net

查看:26
本文介绍了从 vb.net 中的字符串中删除 img 标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有收件箱选项卡,我只想显示正文的 40 个字符,而不是所有正文.具有所有属性意味着完整的 src 但有时它不来意味着 src 可以被剪切.所以如何从正文中删除这个 img 标签并只获取简单的文本.

I have Inbox tab in my project there i want to show only 40 chararacters of body instead of all body.Problem is that if there is img tag exsist in body when i got 40 characters of body using substring sometimes this img tag comes with all attributes means full src but sometime it doesnot come means src can be cut.so how to remove this img tag from body and get only simple text.

推荐答案

为了快速破解,您可以使用如下的正则表达式:

For a quick hack, you can use a regular expression like the following:

Dim input As String = "test<img>" ' your data here
Dim imgRegex As New Regex("<img[^>]*>", RegexOptions.IgnoreCase)
Dim output As String = imgRegex.Replace(input, "")

对于更一般的 HTML 解析,您应该使用 HTML Agility Pack.

For more general HTML parsing, you should use the HTML Agility Pack.

这篇关于从 vb.net 中的字符串中删除 img 标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆