替换/删除两个字符之间的字符串

时间:2014-07-04 03:44:02

标签: vb.net visual-studio-2010 vb.net-2010

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

 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

1 个答案:

答案 0 :(得分:2)

尝试这样

 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