Results 1 to 14 of 14

Thread: [RESOLVED] [2005] Removing a line of text from a .txt file

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2007
    Location
    Portugal
    Posts
    51

    Resolved [RESOLVED] [2005] Removing a line of text from a .txt file

    Hi all

    So...I am writing an app that writes notes, inserted by the user, to a txt file. The app saves that notes to a txt file, and when opening it reads the file and shows the already inserted notes.
    However, I want the user to be able to delete some of those notes...but I can't seem to do it...this is what I have:

    VB Code:
    1. Dim file As New FileStream(data_path & "notes.txt", FileMode.Open)
    2.         Dim text As String = Nothing
    3.         Dim reader As New StreamReader(file)
    4.         Dim writer As New StreamWriter(file)
    5.  
    6.         While Not reader.EndOfStream
    7.             text = reader.ReadLine
    8.             If text.Contains(value) Then
    9.                 text.Replace(value, "")
    10.                 writer.Write(text)
    11.             End If
    12.         End While
    13.  
    14.         file.Close()

    *value is the string/note to be replaced
    *data_path is the path I want...no problems here


    It goes fine, but the text.Replace(value, "") line doesn't seem to work.
    I've also tried text.Remove(0) but it doesn't removes the line...it looks like it has no effect.



    Hope you guys can help me.
    Thanks in advance
    Last edited by buttpt; Feb 24th, 2007 at 03:45 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width