read a line frm txt file and remove it and update the file in vb.net
5 Replies - 829 Views - Last Post: 22 March 2013 - 10:12 AM
#1
read a line frm txt file and remove it and update the file in vb.net
Posted 12 March 2013 - 02:26 AM
Replies To: read a line frm txt file and remove it and update the file in vb.net
#2
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?
#3
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
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
#4
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?
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?
#5
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
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
#6
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|