 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Harald Guest
|
Posted: Tue Dec 09, 2003 10:01 pm Post subject: search and select from a textfile |
|
|
Hi,
I'm trying to copy text from one file to another. I know how the section I
want start and end in the file.
My problem is I only want to copy the section to the new file if I find a
specific word within the section.
I have managed to copy all the selections to a new file, but how do I just
keep the section with the word I'm looking for?
Regards,
Harald
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Tue Dec 09, 2003 10:42 pm Post subject: Re: search and select from a textfile |
|
|
"Harald" <harald_thomsenATyahoo.com> wrote
| Quote: | I'm trying to copy text from one file to another. I know how the
section I want start and end in the file.
My problem is I only want to copy the section to the new file if
I find a specific word within the section.
I have managed to copy all the selections to a new file, but how
do I just keep the section with the word I'm looking for?
|
Between "Pos" and "Copy", you have everything you need. Or would
you prefer that brilliant, elusive component TDoWhatIMean?
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Tom de Neef Guest
|
Posted: Tue Dec 09, 2003 10:54 pm Post subject: Re: search and select from a textfile |
|
|
"Harald" <harald_thomsenATyahoo.com> wrote
| Quote: | Hi,
I'm trying to copy text from one file to another. I know how the section I
want start and end in the file.
My problem is I only want to copy the section to the new file if I find a
specific word within the section.
I have managed to copy all the selections to a new file, but how do I just
keep the section with the word I'm looking for?
Regards,
Harald
|
If you have read the file with Tstringlist.LoadFromFile then every list item
contains one line.
Determine where begin ans end of your section are and delete surrounding
lines.
Then stringlist.SaveToFile to create the new file.
Tom
|
|
| Back to top |
|
 |
HT Guest
|
Posted: Wed Dec 10, 2003 10:05 am Post subject: Re: search and select from a textfile |
|
|
"Harald" <harald_thomsenATyahoo.com> skrev i en meddelelse
news:3fd6473c$0$27442$edfadb0f (AT) dread16 (DOT) news.tele.dk...
| Quote: | Hi,
I'm trying to copy text from one file to another. I know how the section I
want start and end in the file.
My problem is I only want to copy the section to the new file if I find a
specific word within the section.
I have managed to copy all the selections to a new file, but how do I just
keep the section with the word I'm looking for?
Regards,
Harald
|
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific word. The
sections do not have the same size, and the word I'm looking for do not have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
|
|
| Back to top |
|
 |
Tom de Neef Guest
|
Posted: Wed Dec 10, 2003 10:14 am Post subject: Re: search and select from a textfile |
|
|
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote
| Quote: | Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific word.
The
sections do not have the same size, and the word I'm looking for do not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
|
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have them
declared, or transform them to a Tstringlist.
Tom
|
|
| Back to top |
|
 |
Harald Guest
|
Posted: Wed Dec 10, 2003 11:44 am Post subject: Re: search and select from a textfile |
|
|
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
| Quote: | "HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific word.
The
sections do not have the same size, and the word I'm looking for do not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have them
declared, or transform them to a Tstringlist.
Tom
|
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Wed Dec 10, 2003 1:13 pm Post subject: Re: search and select from a textfile |
|
|
On Wed, 10 Dec 2003 12:44:29 +0100, "Harald"
<harald_thomsenATyahoo.com> waffled on about something:
| Quote: | "Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific word.
The
sections do not have the same size, and the word I'm looking for do not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have them
declared, or transform them to a Tstringlist.
Tom
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
|
Going backwards and forwards in a text file is a pain. Personally I
would load the whole thing into a tstringlist and process it from
there.
E.g.
Var
Startline,currentline:integer;
foundit:boolean;
temp:string;
yourstringlist:tstringlist;
begin
yourstringlist:=tstringlist.create;
yourstringlist.loadfromfile('your filename.txt');
foundit:=false;
startline:=0;
For currentline:=0 to yourtstringlist.count-1 do
begin
// lets use a temp variable to save typing!
tempstr:=yourstringlist.strings[currentline];
if tempstr='start' then startline:=currentline
else if tempstr='end' then
begin
if foundit then
begin
foundit:=false;
// We have found a section with the required text
// It runs from startline to the currentline
// So do whatever you like with it.
end;
end
else if pos('what you want',tempstr)<>0 then foundit:=true;
end;
yourstringlist.free;
end;
Hope this helps.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Wed Dec 10, 2003 1:31 pm Post subject: Re: search and select from a textfile |
|
|
On Wed, 10 Dec 2003 13:13:29 +0000, Dodgy
<Dodgy (AT) earth (DOT) planet.universe> waffled on about something:
| Quote: | On Wed, 10 Dec 2003 12:44:29 +0100, "Harald"
harald_thomsenATyahoo.com> waffled on about something:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific word.
The
sections do not have the same size, and the word I'm looking for do not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have them
declared, or transform them to a Tstringlist.
Tom
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
|
Or you could have a tstringlist buffer...
Read the file line by line... When you hit a "Start" set a flag and
write all the strings you read into a tstringlist when this flag is
set... until you hit an "end".
Inside that loop you can also check for the match string you want.
When you get to an end, check you matched boolean flag to see if there
was a hit during that section, if so copy the tstringlist to your
other file. Then empty the tstringlist (you do this even if you don't
have a match). Don't forget to clear your startfound and match flags.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Harald Guest
|
Posted: Wed Dec 10, 2003 1:43 pm Post subject: Re: search and select from a textfile |
|
|
Dodgy,
it looks good. I'll try it when I get home
Cheers
Harald
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> skrev i en meddelelse
news:0q7etvglm9rf0tfme1ejshjd6dhompjcf2 (AT) 4ax (DOT) com...
| Quote: | On Wed, 10 Dec 2003 13:13:29 +0000, Dodgy
[email]Dodgy (AT) earth (DOT) planet.univ[/email]erse> waffled on about something:
On Wed, 10 Dec 2003 12:44:29 +0100, "Harald"
harald_thomsenATyahoo.com> waffled on about something:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific
word.
The
sections do not have the same size, and the word I'm looking for do
not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have
them
declared, or transform them to a Tstringlist.
Tom
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start
to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the
word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
Or you could have a tstringlist buffer...
Read the file line by line... When you hit a "Start" set a flag and
write all the strings you read into a tstringlist when this flag is
set... until you hit an "end".
Inside that loop you can also check for the match string you want.
When you get to an end, check you matched boolean flag to see if there
was a hit during that section, if so copy the tstringlist to your
other file. Then empty the tstringlist (you do this even if you don't
have a match). Don't forget to clear your startfound and match flags.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
|
| Back to top |
|
 |
Harald Guest
|
Posted: Thu Dec 11, 2003 12:35 am Post subject: Re: search and select from a textfile |
|
|
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> skrev i en meddelelse
news:0q7etvglm9rf0tfme1ejshjd6dhompjcf2 (AT) 4ax (DOT) com...
| Quote: | On Wed, 10 Dec 2003 13:13:29 +0000, Dodgy
[email]Dodgy (AT) earth (DOT) planet.univ[/email]erse> waffled on about something:
On Wed, 10 Dec 2003 12:44:29 +0100, "Harald"
harald_thomsenATyahoo.com> waffled on about something:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific
word.
The
sections do not have the same size, and the word I'm looking for do
not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have
them
declared, or transform them to a Tstringlist.
Tom
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start
to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the
word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
Or you could have a tstringlist buffer...
Read the file line by line... When you hit a "Start" set a flag and
write all the strings you read into a tstringlist when this flag is
set... until you hit an "end".
Inside that loop you can also check for the match string you want.
When you get to an end, check you matched boolean flag to see if there
was a hit during that section, if so copy the tstringlist to your
other file. Then empty the tstringlist (you do this even if you don't
have a match). Don't forget to clear your startfound and match flags.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
Hi Dodgy,
I get an error in this program.
It says Match must be Boolean, but I do not know how to do it. The way I've
done it must be wrong.
Does it go through the file the right way?
Regards,
Harald
var oldfile, newfile: TextFile;
oldfileline, matchstring: string;
storeflag: boolean;
match: integer;
selectedtextlist: tstringlist;
begin
deletefile('c:testnewtextfile.txt');
rewrite(newfile, 'c:testnewtextfile.txt');
selectedtextlist := tstringlist.create;
try
storeflag:=false;
assignfile(oldfile,'c:testoldtextfile.txt');
reset(oldfile);
while not eof(oldfile) do
begin
readln(oldfile, oldfileline);
if (pos('START', oldfileline)>0) then
begin
storeflag:=true;
if storeflag then
begin
selectedtextlist.add(oldfileline);
begin
matchstring := copy(oldfileline,39,10);
if matchstring := 'match text in file' then
match := match + 1;
else
match := match;
end
if (pos('END', oldfileline)>0) then storeflag:=false;
if match > 0 then
writeln(newfile, oldfileline);
end;
end;
selectedtextlist.free;
except
showmessage('Could not read Oldfile');
end;
closefile(oldfile);
CloseFile(newfile);
End;
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Thu Dec 11, 2003 10:06 am Post subject: Re: search and select from a textfile |
|
|
On Thu, 11 Dec 2003 01:35:59 +0100, "Harald"
<harald_thomsenATyahoo.com> waffled on about something:
| Quote: | "Dodgy" <Dodgy (AT) earth (DOT) planet.universe> skrev i en meddelelse
news:0q7etvglm9rf0tfme1ejshjd6dhompjcf2 (AT) 4ax (DOT) com...
On Wed, 10 Dec 2003 13:13:29 +0000, Dodgy
[email]Dodgy (AT) earth (DOT) planet.univ[/email]erse> waffled on about something:
On Wed, 10 Dec 2003 12:44:29 +0100, "Harald"
harald_thomsenATyahoo.com> waffled on about something:
"Tom de Neef" <tdeneef (AT) qolor (DOT) nl> skrev i en meddelelse
news:3fd6f2bd$0$216$e4fe514c (AT) news (DOT) xs4all.nl...
"HT" <harald_thomsen (AT) yahoo (DOT) com> wrote in message
news:3fd6ef36$0$266$bc7fd3c (AT) news (DOT) sonofon.dk...
Hi,
I know how to get all the sections.
My problem is, that I only want the sections that have a specific
word.
The
sections do not have the same size, and the word I'm looking for do
not
have
a fixed place in the section.
I've tried with Repeat Until, but I cannot get it to work.
Regards,
Harald
And what then is a 'section'?
Suppose you have a Tsringlist of sections, like
var
sections : Tstringlist;
then you would discard the ones that do not have the specific word:
for i:=sections.count-1 downto 0 do
if pos(searchword,sections[i])=0
then sections.delete(i);
Note that you have to loop down !
If your sections are not in a Tstringlist, then tell us how you have
them
declared, or transform them to a Tstringlist.
Tom
Hi Tom,
I just call the text between start and end for section.
I'm reading the text from a file. I use String, and the text from start
to
end.That works.
But if I only want the sections that contain a specific word I'm lost.
My problem is I do not know to go back to the beginning if I find the
word
I'm and copy the section to a new file.
The file goes like this
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
start
bla bla bla
end
bla bla bla
start I want to get this to the new
file
bla bla bla I want to get this to the new file
bla bla bla I want to get this to the new file
word I want to get this to the new file
bla bla bla I want to get this to the new file
end I want to get this to the new file
bla bla bla
bla bla bla
bla bla bla
start
bla bla bla
bla bla bla
bla bla bla
end
bla bla bla
Harald
Or you could have a tstringlist buffer...
Read the file line by line... When you hit a "Start" set a flag and
write all the strings you read into a tstringlist when this flag is
set... until you hit an "end".
Inside that loop you can also check for the match string you want.
When you get to an end, check you matched boolean flag to see if there
was a hit during that section, if so copy the tstringlist to your
other file. Then empty the tstringlist (you do this even if you don't
have a match). Don't forget to clear your startfound and match flags.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
Hi Dodgy,
I get an error in this program.
It says Match must be Boolean, but I do not know how to do it. The way I've
done it must be wrong.
Does it go through the file the right way?
Regards,
Harald
var oldfile, newfile: TextFile;
oldfileline, matchstring: string;
storeflag: boolean;
match: integer;
selectedtextlist: tstringlist;
begin
deletefile('c:testnewtextfile.txt');
rewrite(newfile, 'c:testnewtextfile.txt');
selectedtextlist := tstringlist.create;
try
storeflag:=false;
assignfile(oldfile,'c:testoldtextfile.txt');
reset(oldfile);
while not eof(oldfile) do
begin
readln(oldfile, oldfileline);
if (pos('START', oldfileline)>0) then
begin
storeflag:=true;
if storeflag then
begin
selectedtextlist.add(oldfileline);
begin
matchstring := copy(oldfileline,39,10);
if matchstring := 'match text in file' then
match := match + 1;
else
match := match;
end
if (pos('END', oldfileline)>0) then storeflag:=false;
if match > 0 then
writeln(newfile, oldfileline);
end;
end;
selectedtextlist.free;
except
showmessage('Could not read Oldfile');
end;
closefile(oldfile);
CloseFile(newfile);
End;
|
So how long have you not been writing Delphi?!
Assignments are variable:=value
Conditionals are variable=value
No colon!
Plus you've got some howling logic bombs ready to explode in there
even if you did get it to compile...
I'll try and straighten it out if I get time today.
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Thu Dec 11, 2003 11:06 am Post subject: Re: search and select from a textfile |
|
|
On Thu, 11 Dec 2003 01:35:59 +0100, "Harald"
<harald_thomsenATyahoo.com> waffled on about something:
| Quote: |
Hi Dodgy,
I get an error in this program.
It says Match must be Boolean, but I do not know how to do it. The way I've
done it must be wrong.
Does it go through the file the right way?
Regards,
Harald
|
This works.
var oldfile, newfile: TextFile;
oldfileline, matchstring: string;
storeflag: boolean;
foundit: boolean;
selectedtextlist: tstringlist;
loop:integer;
begin
// Don't need this... a rewrite will wipe it anyway
// deletefile('c:testnewtextfile.txt');
assignfile(newfile, 'c:tnewtextfile.txt');
rewrite(newfile);
selectedtextlist := tstringlist.create;
try
storeflag:=false;
assignfile(oldfile,'c:toldtextfile.txt');
reset(oldfile);
foundit:=false;
while not eof(oldfile) do
begin
readln(oldfile, oldfileline);
if (pos('START', oldfileline)=1) then
storeflag:=true;
if storeflag then
begin
selectedtextlist.add(oldfileline);
// Following lines changed as a 10 char part of a string will never
// match "match text in file"
// matchstring:= copy(oldfileline,39,10);
// if matchstring= 'match text in file' then
// foundit:=true;
// So this is my match text...
if pos('matchthis',oldfileline)>0 then
foundit:=true;
if (pos('END', oldfileline)=1) then
begin
storeflag:=false;
if foundit then
begin
if selectedtextlist.count>0 then
for loop:=0 to selectedtextlist.count-1 do
begin
writeln(newfile,selectedtextlist.strings[loop]);
end;
foundit:=false;
end;
selectedtextlist.clear;
end;
end;
end;
closefile(oldfile);
except
on e:exception do
begin
showmessage('I had an error: '+e.message);
showmessage('Maybe I could not read Oldfile');
end;
end;
CloseFile(newfile);
selectedtextlist.free;
end;
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Thu Dec 11, 2003 4:43 pm Post subject: Re: search and select from a textfile |
|
|
Hey guys, can you watch your quoting. Repeating the entire history of the
thread on ones response is tedious and annoying.
|
|
| Back to top |
|
 |
Dodgy Guest
|
Posted: Thu Dec 11, 2003 9:54 pm Post subject: Re: search and select from a textfile |
|
|
On Thu, 11 Dec 2003 11:43:46 -0500, "Bruce Roberts"
<ber (AT) bounceitattcanada (DOT) xnet> waffled on about something:
| Quote: | Hey guys, can you watch your quoting. Repeating the entire history of the
thread on ones response is tedious and annoying.
|
Whoops, Sorry Bruce, it did get a bit out of hand...
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
| Back to top |
|
 |
Harald Guest
|
Posted: Fri Dec 12, 2003 8:58 am Post subject: Re: search and select from a textfile |
|
|
Dodgy,
looks great.
Thanx
Harald
"Dodgy" <Dodgy (AT) earth (DOT) planet.universe> skrev i en meddelelse
news:6sphtvg3u14n18moesnjraeercra46qkhv (AT) 4ax (DOT) com...
| Quote: | On Thu, 11 Dec 2003 11:43:46 -0500, "Bruce Roberts"
[email]ber (AT) bounceitattcanada (DOT) xnet[/email]> waffled on about something:
Hey guys, can you watch your quoting. Repeating the entire history of the
thread on ones response is tedious and annoying.
Whoops, Sorry Bruce, it did get a bit out of hand...
Dodgy.
--
MUSHROOMS ARE THE OPIATE OF THE MOOSES
|
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|