且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除文本文件中的文本

更新时间:2022-06-15 09:47:14

你没有在你的 StringBuilder 对象,因此无需删除任何内容。即使你这样做,该对象也不会在别处使用,所以它没有用处。你的逻辑应该是错误的方式:

You do not put any text in your StringBuilder object, so there is nothing to remove. And even if you did, the object is not used elsewhere so it serves no purpose. Your logic is the wrong way round it should be:
Dim sb As New System.Text.StringBuilder
For Each line In IO.File.ReadLines("C:\_Montix a.s. - cloud\iMontix\aaa.txt")
    If (Not line.StartsWith(TextBox1.Text)) Then
        sb.Append(line) ' add lines that are not in the textbox
    End If
Next
' store the resultant string somewhere