替换/删除两个字符之间的字符串 [英] Replace / Remove String between two characters

查看:83
本文介绍了替换/删除两个字符之间的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始创建一个代码(在 VB.NET 中)来从文本中提取信息;我在 StackOverflow 和搜索引擎中找不到的东西是替换/删除<"之间的文本的示例和>"可能是 REPLACEREGEX;我两个都试过,但无法弄清楚;我能得到一些帮助吗....非常感谢...

I started to create a code (in VB.NET) to extract information from texts; The thing that I could not find in StackOverflow and search engines is an example of replacing/removing the text between "<" and ">" Probably it is REPLACE or REGEX; I tried both, but could not figure it out; Can I get some help.... Much appreciated...

 Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Dim SSSS = Replace(Label1.Text, "<td>", vbNewLine, 1, , CompareMethod.Text)

    MessageBox.Show(SSSS)
End Sub
End Class

如果我有 <td>; 以上(在 VB.NET 中)会将我的文本分成几行;但我想添加以下内容:我正在处理的文本是:test1<img alt='dddddd' src='https://mekdam.com'><div class='what'>test2</div><div class='code'>more</div>我想从 VB.NET 中获取 test1 test2

The above (in VB.NET) will split my text into line if I have <td>; but I want to add the following: My Text I am working on is: test1<img alt='dddddd' src='https://mekdam.com'><div class='what'>test2</div><div class='code'>more</div> I want to get test1 test2 from that in VB.NET

推荐答案

Try Like this

Try Like this

 Private Sub StrRep(ByVal xstr As String)

        Dim xst As Integer = xch.IndexOf("<")
        Dim xend As Integer = xch.IndexOf(">")

        Dim xsub As String = xstr .Substring(xst, (xend - xst) + 1)
        xstr = xstr .Replace(xsub, String.Empty)

        If xstr .Contains("<") Then
            Call StrRep(xstr )
        Else
            MsgBox(xstr )
        End If

    End Sub

这篇关于替换/删除两个字符之间的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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