从行 richtextbox vb.net 中删除特殊字符串

remove speical string from lines richtextbox vb.net

我有一个 richtextbox,里面有很多这样的行 `Batman=games\file.exe

Batman=games\file\spid.exe

SNaruto=games\file\spid.exe

spiderman=blue\spk.exe

game=gigi.exe

我正在尝试让按钮删除 = 之后的所有文本,就像这样

Batman

SNaruto

spiderman

game

甚至

Batman=

SNaruto=

spiderman=

game=

谢谢

你很幸运,我从早上开始就一直在努力编写与你想要的类似的代码,我们开始吧我对我的代码进行了一些更改以满足你的要求

Dim x As String = ""
        Dim y As String = ""
        For Each strLine As String In TextBox1.Text.Split(vbNewLine) 'TO read each line in text box
            Dim ii As Integer = strLine.Length
            Dim i As Integer = 0
            For i = 0 To ii - 1
                y = strLine.Substring(i, 1)
                If y = "=" Then
                    x = strLine.Substring(0, i)
                    TextBox2.AppendText(x & Environment.NewLine)
                End If
            Next
        Next

试试这个:

For x = 0 To RichTextBox1.Lines.Length - 1
    Dim i As Integer = RichTextBox1.Lines(x).IndexOf("=")
    If i <> -1 Then
        RichTextBox1.Lines(x) = RichTextBox1.Lines(x).Remove(i)
    End If
Next

关于使用的属性和方法的一些解释:

RichTextBox.Lines() 属性 是一个字符串数组,其中每个 element/object 代表 RichTextBox 中的一行。 阅读更多: https://msdn.microsoft.com/en-us/library/system.windows.forms.textboxbase.lines(v=vs.110).aspx

IndexOf 方法return 指定字符串中的字符或字符串的索引。如果什么也没找到,它 returns -1。对于错误,我们检查 IndexOf 不会 return -1。这就是我们使用 If i <> -1 Then 的原因,其中 <> 表示 "Not equal to"。 阅读更多: https://msdn.microsoft.com/en-us/library/system.string.indexof(v=vs.110).aspx

Remove方法将从指定的字符串中删除一定数量的字符,从指定的开始位置开始。然后它将删除所有字符,包括位于指定起始位置的字符以及之后的字符。 阅读更多: https://msdn.microsoft.com/en-us/library/system.string.remove%28v=vs.110%29.aspx