By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,819 Members | 1,573 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,819 IT Pros & Developers. It's quick & easy.

How do I trigger the writeline method to write to a text file by keyword and end another key word

P: n/a
Any code on how to start write to a new file would be appreciated. In
the example below: How would I start the write to a file on the word
"Recipe" and then write every line beneath it until "End of Recipe"

dfgsdgfsdfgsdgf
dgfsdfgdfgsdfsdfgsdfg
"Recipe"
edsadfasdfasdfasdfasdf
sadfasdf5twtgfvdfgdfgdsfg
rgg5345454ygdfgdgfdsgdsf
dfgsdgsdfgsdfg
"End of Recipe"
dsfgsdgsdfgsdfgsdfgsdfg5g
dfgsdfgsfgsfgsdfgsdfgsdfg435

Again, any code to at least get me started with the trigger to start
the write to file would be great!

Thanks!

Apr 23 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Something like this?

**********************************
Required: "Imports System.IO.FileStream"

Dim streamR As StreamReader = New StreamReader("C:\Temp\Input.txt")
Dim streamW As StreamWriter = New StreamWriter("C:\Temp\Output.txt")

While Not streamR.EndOfStream
strInput = streamR.ReadLine
If InStr(strInput, "Begin of Recipe", CompareMethod.Text) 0 Then
strInput = streamR.ReadLine
If Not InStr(strInput, "End of Recipe", CompareMethod.Text) 0 Then
streamW.WriteLine(strInput)
End If
streamW.Flush()
streamW.Close()
End If
End While

streamR.Close()
**********************************

HTH, CoRrRan

Quentin wrote:
Any code on how to start write to a new file would be appreciated. In
the example below: How would I start the write to a file on the word
"Recipe" and then write every line beneath it until "End of Recipe"

dfgsdgfsdfgsdgf
dgfsdfgdfgsdfsdfgsdfg
"Recipe"
edsadfasdfasdfasdfasdf
sadfasdf5twtgfvdfgdfgdsfg
rgg5345454ygdfgdgfdsgdsf
dfgsdgsdfgsdfg
"End of Recipe"
dsfgsdgsdfgsdfgsdfgsdfg5g
dfgsdfgsfgsfgsdfgsdfgsdfg435

Again, any code to at least get me started with the trigger to start
the write to file would be great!

Thanks!
Apr 23 '07 #2

P: n/a
On Apr 23, 9:15 am, CoRrRan <CoRrRan~NOSPAM~@~NOSPAM~gmail.comwrote:
Something like this?

**********************************
Required: "Imports System.IO.FileStream"

Dim streamR As StreamReader = New StreamReader("C:\Temp\Input.txt")
Dim streamW As StreamWriter = New StreamWriter("C:\Temp\Output.txt")

While Not streamR.EndOfStream
strInput = streamR.ReadLine
If InStr(strInput, "Begin of Recipe", CompareMethod.Text) 0 Then
strInput = streamR.ReadLine
If Not InStr(strInput, "Endof Recipe", CompareMethod.Text) 0 Then
streamW.WriteLine(strInput)
EndIf
streamW.Flush()
streamW.Close()
EndIfEndWhile

streamR.Close()
**********************************

HTH, CoRrRan

Quentin wrote:
Any code on how to startwriteto a newfilewould be appreciated. In
the example below: How would I start thewriteto afileon theword
"Recipe" and thenwriteevery line beneath it until "Endof Recipe"
dfgsdgfsdfgsdgf
dgfsdfgdfgsdfsdfgsdfg
"Recipe"
edsadfasdfasdfasdfasdf
sadfasdf5twtgfvdfgdfgdsfg
rgg5345454ygdfgdgfdsgdsf
dfgsdgsdfgsdfg
"Endof Recipe"
dsfgsdgsdfgsdfgsdfgsdfg5g
dfgsdfgsfgsfgsdfgsdfgsdfg435
Again, any code to at least get me started with thetriggerto start
thewritetofilewould be great!
Thanks!- Hide quotedtext-

- Show quotedtext-
I could get the code to work so I tried what I post below and it still
didn't work. I moved some data, but still wasn't getting the stuff
between Recipe and End of Recipe

Dim streamR As StreamReader = IO.File.OpenText("c:\MultiTemp1.txt")
Dim streamw As StreamWriter = IO.File.CreateText("c:
\filtered2.txt")
Dim strInput As String

While Not streamR.EndOfStream
strInput = streamR.ReadLine

If strInput.Contains("End") Then
Else
If InStr(strInput, "Recipe", CompareMethod.Text) >= 0
Then
strInput = streamR.ReadLine
streamw.WriteLine(strInput)
End If
End If
End While

streamw.Flush()
streamw.Close()

streamR.Close()

Thanks for the help you have already given me..do have any other
suggestions? Thanks!

Apr 25 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.