Delete specific lines in a text file using vb.net

前端 未结 3 848
太阳男子
太阳男子 2020-12-21 14:37

I am trying to delete some specific lines of a text using VB.Net. I saw a solution here however it is in VB6. The problem is, I am not really familiar with VB6. Can somebody

相关标签:
3条回答
  • 2020-12-21 14:40
    Dim delLine As Integer = 10
    Dim lines As List(Of String) = System.IO.File.ReadAllLines("infile.txt").ToList
    lines.RemoveAt(delLine - 1) ' index starts at 0 
    System.IO.File.WriteAllLines("outfile.txt", lines)
    
    0 讨论(0)
  • 2020-12-21 14:41

    Or You Can Use

    TextFile = TextFile.Replace("You want to Delete","")

    0 讨论(0)
  • 2020-12-21 14:54
        'This can also be the file that you read in
        Dim str As String = "sdfkvjdfkjv" & vbCrLf & "dfsgkjhdfj" & vbCrLf & "dfkjbhhjsdbvcsdhjbvdhs" & vbCrLf & "dfksbvashjcvhjbc"
    
        Dim str2() As String = str.Split(vbCrLf)
    
        For Each s In str2
            If s.Contains("YourString") Then
                'add your line to txtbox
            Else
                'don't add your line to txtbox
            End If
        Next
    
    0 讨论(0)
提交回复
热议问题