Download MetaTrader 5

How to find a word from a sentence with stringfind?

To add comments, please log in or register
Mimi
501
Mimi  

Hi 

I have an indicator which reads from a csv file. Now after fetching the data it stored in Description which is a string data type.

On Description data are stored in following manners: 

"Apple Fruit"

"Potato Vegetables" 

Using stringfind I want to fetch only Fruit.

I am doing this:

int comp = StringFind(Description,"Fruit",0);

 But it returns comp = -1 all the time. Even if there is a data similar to fruit available on the csv file.

 Please help how to do this.

Thank you in advance. 

Carl Schreiber
6693
Carl Schreiber  
Provide the full code to get help!
peter.MT4Web
158
peter.MT4Web  

You can be shure that StringFind works correct.

Maybe there is a "fruit" in Description and no "Fruit" ?

You have to check each line of the csv-file seperately.

Keith Watford
Moderator
9644
Keith Watford  
Do a small test and Print Description before using StringFind to make sure that "Fruit" is in the string variable
Mimi
501
Mimi  

Thank you everybody for such a quick reply. Actually I figure, its happening because of the space. If I search for Apple then its not problem. But if I search for Fruit, then it creates problem. In case of stringfind I need to give start point, I use 0 as start point. But as soon it hit space, I guess it stopped there. 

So I need to find where the space is located. So that In stringfind I can search after the space.

Any idea?

Thank you again. 

peter.MT4Web
158
peter.MT4Web  

A space is no problem for StringFind!

Check what's in Description.

Mimi
501
Mimi  
eddie:

A space is no problem for StringFind!

Check what's in Description.

Yes checked it out. 
I am extremely sorry, I made a silly mistake, space is not a problem. 

Search type spelling was wrong.

I Solved it now.. Thank you again..

Have a nice day... everybody... 

To add comments, please log in or register