Link to home
Start Free TrialLog in
Avatar of jhoughton7677
jhoughton7677

asked on

Extract block of text from text file c#

I need to open a text file, extract a block of text from it (from [TEST] to [TESTEND] and write that block to another file.
I'm pretty new to c# but I understand I need to read it with stream reader, then do some kind of split before using streamwriter to publish it, but I don't know how to split that out.

The file I will be opening will look something like this... (Obviously the words will be different)

NOCOPY
NOCOPY
NOCOPY
NOCOPY
NOCOPY
[TEST]
COPY1
COPY2
COPY3
COPY4
COPY5
[TESTEND]
NOCOPY
NOCOPY
NOCOPY
NOCOPY
NOCOPY
SOLUTION
Avatar of Ravi Vaddadi
Ravi Vaddadi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jhoughton7677
jhoughton7677

ASKER

PS. I know it looks rough, but I'm only working on the idea right now. I will clean it up later.
Nevermind I figured it out by adding

                    int i2 = fileread.IndexOf("[TESTEND]");
                    int i3 = i2 - i;

Thanks for the the help SriVaddadi.