Replace / Remove String between two characters

◇◆丶佛笑我妖孽 提交于 2019-12-08 03:17:02

问题


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

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


回答1:


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


来源:https://stackoverflow.com/questions/24566393/replace-remove-string-between-two-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!