How to search for a particular text inside a text file ?

 

I want to search the text "MESSAGE" in a particular txt file in files folder.

 

With MQL for text files simplest thing is to read line by line from the field and then search inside the line with StringFind() function.

 

Ctrl + F

 
Sebastian Niemiec:

Ctrl + F

i was programatic search
 
balachandran chandrasekar:
i was programatic search
Please show your attempt.
 
Alain Verleyen:
Please show your attempt.
int fhandle=FileOpen("blg.txt",FILE_READ|FILE_BIN);

string want,str2;

string str;
str= FileReadString(fhandle,100000);
want="MESSAGE";
k=StringFind(str,want,2);
c=FileTell(1);
g=c-k-7;
FileSeek(fhandle,-g,SEEK_CUR);
str= FileReadString(fhandle,250);

c=FileTell(1);
//Alert("cp",c);
FileSeek(fhandle,-187,SEEK_CUR);
str2= FileReadString(fhandle,200);

b=StringFind(str,"<div",2);
str=StringSubstr(str,0,b);
 
balachandran chandrasekar:

Ok. You read the data in a buffer (string) and use StringFind(), seems correct approach.

And what is the problem ?

 
Alain Verleyen:

Ok. You read the data in a buffer (string) and use StringFind(), seems correct approach.

And what is the problem ?

i download  a blogsites home page. my need is to extract the last post. each post will have the starting word MESSAGE and then some txt.

But when i use that it was extracting text from the first line of the file.

i have one doubt . What is the maximum buffer size ? how much characters it can hold ?

the file size was some what 80 KB.

Whether that may be an issue ? 

 

Meanwhile i have found some other way to do it.

but still i want to know, what went wrong in the previous code 

Reason: