5 Replies - 2831 Views - Last Post: 22 March 2013 - 10:12 AM Rate Topic: -----

#1 dazzler helal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 13

read a line frm txt file and remove it and update the file in vb.net

Posted 12 March 2013 - 02:26 AM

read a line frm txt file and remove it and update the file in vb.net
Is This A Good Question/Topic? 0
  • +

Replies To: read a line frm txt file and remove it and update the file in vb.net

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: read a line frm txt file and remove it and update the file in vb.net

Posted 12 March 2013 - 05:13 AM

And how have you attempted to do this?
Was This Post Helpful? 0
  • +
  • -

#3 dazzler helal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 13

Re: read a line frm txt file and remove it and update the file in vb.net

Posted 16 March 2013 - 11:09 PM

[quote name='CharlieMay' date='12 March 2013 - 05:13 AM' timestamp='1363090411' post='1818327']
And how have you attempted to do this?
[/but i cant write through this on desired place it just append at last]
Dim fs = File.Open("C:\abdul\play.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Dim objReader = New StreamReader(fs)

Dim text As String = Nothing
Do While objReader.Peek() <> -1
text = objReader.ReadLine()
MessageBox.Show(text)
If text.Equals(ComboBox1.SelectedItem) Then
text = text.Replace(ComboBox1.SelectedItem, "")

fs.Close()
objReader.Close()
fs = File.Open("C:\abdul\play.txt", FileMode.Append, FileAccess.Write, FileShare.ReadWrite)
Dim n As Integer = text.IndexOf(ComboBox1.SelectedItem)
Dim fw = New StreamWriter(fs)
fw.WriteLine(text)
fw.Flush()
fs.Close()
fs = File.Open("C:\abdul\play.txt", FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
objReader = New StreamReader(fs)
Else
MessageBox.Show("not found")
End If
Loop
Was This Post Helpful? 0
  • +
  • -

#4 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 278
  • View blog
  • Posts: 884
  • Joined: 01-February 13

Re: read a line frm txt file and remove it and update the file in vb.net

Posted 17 March 2013 - 06:20 AM

Hello dazzler helal,
Do you have to do it this way or are you allowed to do it however you want? I ask because you could just read the whole file into a string array, then remove the words, and then just overwrite the existing file. I think it would be easier that way. Also does your text file have just one word per line or full sentences in each line?
Was This Post Helpful? 0
  • +
  • -

#5 dazzler helal  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 12-March 13

Re: read a line frm txt file and remove it and update the file in vb.net

Posted 22 March 2013 - 08:08 AM

i cant do that like read whole file in string array suppose if there is two similar line is there
in my file then all will be replaced by space .i want that perticular line is read and delete or replaced by space
please give me proper solution

i cant do that like read whole file in string array suppose if there is two similar line is there
in my file then all will be replaced by space .i want that perticular line is read and delete or replaced by space
please give me proper solution
Was This Post Helpful? 0
  • +
  • -

#6 IronRazer  Icon User is offline

  • D.I.C Addict

Reputation: 278
  • View blog
  • Posts: 884
  • Joined: 01-February 13

Re: read a line frm txt file and remove it and update the file in vb.net

Posted 22 March 2013 - 10:12 AM

It is not clear what your goal is by the way your code is set up and by what you are saying you want and don`t want it to do. Do you want to replace all the lines in the text file that match the selected item in combobox1 or do you want to choose a certain line or lines in the text file that match the selected item in combobox1 and replace it ? Please make it clear of what you want your code to do. :unsure:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1