I know How to Delete a Textfile , I even know how to write the temp string data into a TextFile. But i do noy know how to delete from String array,into which i read all the data of the file. Mine Code is as under,Plz help me out. I will ber very thankful to U.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim RowNum As ListViewItem

        For Each RowNum In ListView2.SelectedItems
            ListView2.Items.Remove(RowNum)
        Next


        Dim arrlines() As String = IO.File.ReadAllLines("c:\Records.txt")

End sub

If you only want to delete some records from the file, consider loading them into your ListView, removing the listview items you don't need, then write the listview data back to the file...

Hope this helps

Did you find the solution? If so can you please close this thread by marking it as Solved. And please leave a post with your fix as this will help other forum users.

I do not delete from String Array,To do wat i wanted....I use the another method..I still do not know how to delete from string array.

Hi,

I see you have the contents of the text file in the array arrlines.
Then, guess that you have the value you want to delete in the valueToDel variable:

...
        Dim c As Integer = 0
        Dim valueToDelete As String = "some string"
        Dim arrLinesTemp() As String
        Dim arrLines() As String = IO.File.ReadAllLines("c:\Records.txt")

        ' Make a copy of the original array avoiding the value
        ' you want to delete
        For x As Integer = 0 To UBound(arrLines)
            If arrLines(x) <> valueToDelete Then
                arrLinesTemp(c) = arrLines(x)
                c += 1
            End If
        Next x

        ' Clear the original array
        Array.Clear(arrLines, 0, UBound(arrLines))

        ' Restore the values left in the original array
        Array.Copy(arrLinesTemp, arrLines, UBound(arrLinesTemp))
        ...

I am sure that there are better ways to do this. But it just works! :D

This article has been dead for over six months. Start a new discussion instead.