Find word in text file and write a line

sputnik

Member
Joined
Oct 11, 2005
Messages
10
Programming Experience
5-10
How can I open a text file, find a certain word in the text file, and then, just before that word, write a line of text to the file - then save the file?
 
Look up the following :
VB.NET:
System.IO.StreamReader()
String.Contains()
String.Insert()
oh and also
VB.NET:
System.IO.StreamWriter()
and
My.Computer.FileSystem.WriteAllText() 'dont know if i got the method name correct
 
Last edited:
the problem I'm having now - - I get the position of the string I'm looking for no problem
However, when I do String.Insert(position, NewText), it never actually adds the text - - I tried this with 2 textboxes:
Dim ENew As String = TextBox1.Text
Dim pos As Long
pos = ENew.IndexOf("TheTextIAmLookingFor") - 1 ' I get a good number here for the position

ENew.Insert(pos, "AAAAA")
TextBox2.Text = ENew
TextBox2.SelectionStart = TextBox2.Text.IndexOf("AAAAA") '<<< right here, it never finds that position - it gives me a -1 and I can't see 'AAAAA ' in the textbox
TextBox2.SelectionLength = 5
 
Back
Top