I want help in write a code...

mhb-ksa

Member
Joined
Apr 20, 2006
Messages
5
Hi
I have a problem with vb.net

I want write a code to search for line in text file and removed just the line

For example

In form, I have Textbox, in the textbox I was wrote a sentence "Hi, you will remove this line". And I have a button, I want when I click in this button I want removed this line from the text file "notepad"

For example in text file
 
If you search the forums then this question has been asked and answered before. In summary you would need to read each line from the old file into a new file and just dont write out the lines you wish to remove.
You would then replace the old file with the new one.
 
Hi guys
I was found the code
this code for erase line or more from text file

In my program I have 7 textbox , It is 1 record

the task for my program add and remove a record from text file, like database
Code:
         Dim read As IO.StreamReader
        Dim wite As IO.StreamWriter
        Dim a, line As String
        Dim nu As Integer
        Dim SB As System.Text.StringBuilder = New System.Text.StringBuilder
        a = TextBox1.Text

        read = IO.File.OpenText("c:\studata.txt")
        Do
            line = read.ReadLine
            If line = a Then
                For nu = 1 To 6
                    read.ReadLine()
                Next nu
                line = read.ReadLine
            End If
            SB.Append(line)
            SB.Append(System.Environment.NewLine)
        Loop Until line = ""
        read.Close()

        wite = IO.File.CreateText("c:\studata.txt")
        wite.Write(SB.ToString())
        wite.Close()
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
        TextBox5.Clear()
        TextBox6.Clear()
        TextBox7.Clear()

I am sorry about my english language , I am arabian guy

Thanks for PlausiblyDamp , Diesel and Nerseus to help me
 
Back
Top