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

Q

Quentin

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!
 
C

CoRrRan

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
 
Q

Quentin

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







- 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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top