Results 1 to 3 of 3

Thread: [2005] [delete string in file]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Resolved [2005] [delete string in file]

    Hi Friends ,

    i want to delete the particular string (content) in file .. how to search the content to delete .. or any other way to solve this problem .. how to do this .. plz help me..
    Last edited by manju.cdtech; Mar 26th, 2007 at 11:52 PM.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] [delete string in file]

    This question has been asked and answered in various guises multiple times. You have to read the whole file in and then write it out again minus the line in question. There are numerous variations but I'd do it something like this:
    vb Code:
    1. Dim filePath As String = "file path here"
    2. Dim target As String = "target string here"
    3. Dim lines As String() = IO.File.ReadAllLines(filePath)
    4.  
    5. Using writer As New IO.StreamWriter(filePath)
    6.     For Each line As String In lines
    7.         If line <> target Then
    8.             writer.Write(line)
    9.         End If
    10.     Next line
    11. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2007
    Posts
    98

    Re: [2005] [delete string in file]

    ya its working fine .. thanks

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