First off, I would like to thank those who have given me help so far!
I would like to remove all the lines of data above the word Recipe in
a text file and all the lines below the words "End of Recipe" in this
file. I want to keep everything inbetween these two lines. Below is
a small sample of my text file and the code I have so far.
2,3,5,6,56,7,4, 7,,,56,5,7,
-1,45,4,451,7,66 ,7,667,
"Recipe KX009.RCP, Date=02/11/07, Time=12:20:27,
2532,45,23,5,34 ,52345,,34,5234 ,345,45
3,34523452,45,3 245,245,343443, 344,45
,3445,4,45,,26, 234,5,24,5145,5 ,65,56,5
"End of Recipe"
4,5,6,3,7,,8,6, 8,68
,67,6,87,6,78,6 ,76
,243,7,76,9,7,9 ,6,,
Dim streamR As StreamReader = IO.File.OpenTex t("c:\MultiTemp 1.txt")
Dim streamw As StreamWriter = IO.File.CreateT ext("c:
\filtered2.txt" )
Dim strInput As String
While Not streamR.EndOfSt ream
strInput = streamR.ReadLin e
If strInput.Contai ns("End") Then
Else
If InStr(strInput, "Recipe", CompareMethod.T ext) >= 0
Then
strInput = streamR.ReadLin e
streamw.WriteLi ne(strInput)
End If
End If
End While
streamw.Flush()
streamw.Close()
streamR.Close()
Thanks for your Help! 1 1684
I realize it's probably not a recognized way of doing things, but when I
have to extract text from a string where I know the start and end
identifier, I normally use the Split function. You can do it in two lines of
code:
Dim TempArray() As String = Split(OriginalS tring, "Recipe")
ExtractedString = TempArray(1).Su bstring(0, TempArray(1).Le ngth - 8).Trim
TempArray(0) will contain the text before the first Recipe
TempArray(1) will contain the text between the two Recipe's
TempArray(2) will contain the text after the last Recipe
If both the starting and the ending identifier had been the same, you could
simply have used TempArray(1), but because of the "End of" and the quote
signs, a little more manipulation is needed. You remove the last 8
characters and trim the string (with your example, there will be a space in
the beginning of TempArray(1) ).
Good luck,
Johnny J. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Row |
last post by:
HI,
I would first like to say its been about 3 years since looking at java
im very rusty!
I have to write a post it notes type applet which will function
online. (reading from a flat text file)
My main problem is: getting each paragraph into my vector array - so
that each paragraph sits in a new array element. Eg: when i referance
array elemant 2 it will give me paragraph which is in that element and
not all paragraphs in the text file...
|
by: peraklo |
last post by:
Hello,
there is another problem i am facing. i have a text file which is
about 15000 lines big. i have to cut the last 27 lines from that file
and create a new text file that contans those 27 lines. and after that
save both of those files... since that is a big block of text (15000
lines) i thint that it is a big job to look for a keyword... so my
question is this exactly:
how do i do this:
|
by: Quentin |
last post by:
I have a text file with lines that I would like to remove above a
certain word and below another word.
Example:
1231231231234123423434
2341234123412341242141
234512353764316236234
1235635326235125134534
Recipe
|
by: Quentin |
last post by:
First off, I would like to thank those who have given me help so far!
I would like to remove all the lines of data above the word Recipe in
a text file and all the lines below the words "End of Recipe" in this
file. I want to keep everything inbetween these two lines. Below is
a small sample of my text file and the code I have so far.
2,3,5,6,56,7,4,7,,,56,5,7,
-1,45,4,451,7,66,7,667,
"Recipe KX009.RCP, Date=02/11/07, Time=12:20:27,
|
by: Francois Appert |
last post by:
This post was originally in the C# Corner site, but their server is
down. I'd like to see if this group can answer.
I program in C++ and am learning C#.
The issue is: why should anybody bother in C# with pass-by-reference
using the "ref" keyword or "out" for objects in a method parameter
list, when, after all, it appears in C# that for all intents and
purposes a reference is always being passed, rather than the real
object (with, it...
| |
by: kanley |
last post by:
I have a main table with a text description field. In this field, its
populated with a string of data. I need to identify from this string
of data the name of the vendor using some keywords.
I have another table that contains 2 fields, one being the keywords to
search for from the string of data and the other field being the
vendor name to pair up with the record.
How do I reference the keywords from the 2nd table and search thru the...
|
by: arnuld |
last post by:
I have created a program which creates and renames files. I have
described everything in comments. All I have is the
cod-duplication. function like fopen, sprint and fwrite are being called
again and again.
I know to remove code-duplication I have to make functions and pass
arguments to them but I am not able to think of a way doing it. Can you
post some example for me, out of this code:
|
by: Allen Chen [MSFT] |
last post by:
Hi Richard,
Quote from Richard==================================================
However I also want to be able to remove the
panes. I have tried to include this, but find that when I first add the
pane
the remove event does not get handled, though thereafter it is handled
without problems.
==================================================
|
by: rka77 |
last post by:
Hi,
I am trying to make a Python2.6 script on a Win32 that will read all the text files stored in a directory and print only the lines containing actual data. A sample file -
Set : 1
Date: 10212009
12 34 56
25 67 90
End Set
********
Set: 2
Date: 10222009
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |