Link to home
Start Free TrialLog in
Avatar of moutaz_ima
moutaz_ima

asked on

search for string within text file

How Can I Read Specific String whithin very Very Large
Text File with High performance,

please Advice me as soon as posible.

thanks
Avatar of DaFox
DaFox

Hi.

Do a search on the net for Boyer-Moore Horspool. AFAIK that's one of the best search algorithms for large texts.

Markus
I gather the problem is more that the text won't fit into a Tmemo, or whatever.

I believe you should examine conventional file-handling, with specific reference to BLOCKREAD, and then do a byte-by-byte scan on the data read.

Whereas smartening up the program is nice academically, it might be of little practical value with the speed of today's machines when compared with the I/O time for the file to be physically read from the mass media.

A simple speed-up could be to find the character in your search-for string that has the LOWEST usage rate in the text file in question. For instance, if your text file is in English, and you have a Q as the third character in your search-string, search for the Q, then try to match your string starting at buffer[q_location_found - position_of_q_in_search_string]

If you have no q's, then try J,Z,X, etc. There should be a letter-frequency list somewhere on the net!

HTH

...Bill
text files have a sequentional acces

if the text file is samler then 32kb of text u mey use
memo component
memo1.loadfromfile('filepath+filename');
and after that u use standard memo command

u mey also use
tstrings  and again loadfromfile metod


but the fastest metod is the foloving
if u search for some string in the textfile;

proceure searchtext(s:string):string;
var f:textfiel;
    sq:string;
begin
assign(f,'filepath+filename);
reset(f);
while not eof(f) do
begin
 readln(f,sq);
 if pos(s,sq)>0 then begin break; end;   {here u mey do enything u wont i u search for strign from textfile }
end;
closefile(f);
end;

procedure getcolmun(i:longint);
i1:longint;
begin
assign(f,'filepath+filename);
reset(f);
i1:=0;
while not eof(f) do
begin
 readln(f,sq);
 inc(i1);
  if i=i1 then  begin  {in the sq is the i-th line of text from textfile}      break;    end;
end;
closefile(f);

end;




text files have a sequentional acces

if the text file is samler then 32kb of text u mey use
memo component
memo1.loadfromfile('filepath+filename');
and after that u use standard memo command

u mey also use
tstrings  and again loadfromfile metod


but the fastest metod is the foloving
if u search for some string in the textfile;

proceure searchtext(s:string):string;
var f:textfiel;
    sq:string;
begin
assign(f,'filepath+filename);
reset(f);
while not eof(f) do
begin
 readln(f,sq);
 if pos(s,sq)>0 then begin break; end;   {here u mey do enything u wont i u search for strign from textfile }
end;
closefile(f);
end;

procedure getcolmun(i:longint);
i1:longint;
begin
assign(f,'filepath+filename);
reset(f);
i1:=0;
while not eof(f) do
begin
 readln(f,sq);
 inc(i1);
  if i=i1 then  begin  {in the sq is the i-th line of text from textfile}      break;    end;
end;
closefile(f);

end;




moutaz_ima:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
Hi!
No comment has been added lately and this question is therefore classified abandoned.

If asker wishes to close the question, then refer to
https://www.experts-exchange.com/help/closing.jsp

Otherwise, I will leave a recommendation in the Cleanup topic area that this question is:

PAQ'd and pts refunded

Please leave any comments here within the next seven days. It is assumed that any participant not responding to this request is no longer interested in its final disposition.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

...Snehanshu
EE Cleanup Volunteer
ASKER CERTIFIED SOLUTION
Avatar of modulo
modulo

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