Download MetaTrader 5
To add comments, please log in or register
Having questions to the author of an article? Discuss them on the Forum!
KoT 009
44107
KoT 009 2015.05.19 15:57 

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

Drazen Penic
2538
Drazen Penic 2015.05.19 19:21  

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.

Sebastian Niemiec
906
Sebastian Niemiec 2015.05.20 00:07  

Ctrl + F

KoT 009
44107
KoT 009 2015.05.20 03:16  
Sebastian Niemiec:

Ctrl + F

i was programatic search
Alain Verleyen
Moderator
30640
Alain Verleyen 2015.05.21 14:06  
balachandran chandrasekar:
i was programatic search
Please show your attempt.
KoT 009
44107
KoT 009 2015.05.21 16:06  
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);
Alain Verleyen
Moderator
30640
Alain Verleyen 2015.05.21 16:10  
balachandran chandrasekar:

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

And what is the problem ?

KoT 009
44107
KoT 009 2015.05.21 18:03  
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 ? 

KoT 009
44107
KoT 009 2015.05.21 18:04  

Meanwhile i have found some other way to do it.

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

/
To add comments, please log in or register