473,511 Members | 15,126 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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
2 1611
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7516
by: Lo?c Mah? | last post by:
Hello I try to use a Validator for a TxtCtrl placed in a Panel with a Button in order to trigger the Validator and test the content of TxtCtrl. I have looked into wxPython documentation and...
3
10822
by: Terri | last post by:
I'm using xp_cmdshell to output a text file from a trigger like this CREATE TRIGGER ON tblApplications FOR INSERT AS DECLARE @FirstName varchar(75) DECLARE @LastName varchar(75) Declare...
9
11205
by: Lauren Quantrell | last post by:
Is there a way to create a text file (such as a Windows Notepad file) by using a trigger on a table? What I want to do is to send a row of information to a table where the table: tblFileData has...
12
11049
by: Nina | last post by:
Hi there, What is the maximum length that one line can hold in a text file using StreamWriter's Write or WriteLine method? If the string is too long for one line to hold, what will Write or...
1
13712
by: tenspeeddrive | last post by:
According the MSDN,... The Print/PrintLine functions write display-formatted data to a sequential file....
2
2933
by: djc | last post by:
out of all the overloads that pop up via intellisense for console.writeline() the following one confuses me: Console.WriteLine (string format, params object arg) 1) whats the deal with...
9
9297
by: Ots | last post by:
I'm using SQL 2000, which is integrated with a VB.NET 2003 app. I have an Audit trigger that logs changes to tables. I want to apply this trigger to many different tables. It's the same trigger,...
1
1740
by: Sarahger9 | last post by:
I wrote a program that searched a file word by word, looking for keywords from another file that needed to be replaced in the first file. I did this, but I need to state an error message if one of...
1
2551
by: bwestover | last post by:
I am trying to pull data out of an application database and transform it to another medium. I have direct access to the database, but I cannot alter the program code. What I want to have happen...
0
7417
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7074
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7506
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5063
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4734
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3219
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3210
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
780
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
445
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.