How to search an array with string values?

 

Suppose I have an array called StringArray[ ] filled with five string values like shown below:

StringArray[5] = {"ABC100","XYZ100","ABC200","XYZ200","ABC300"}

I want to search this array for all string values starting with "ABC".

The desired answer would be the position of these elements in the array, i.e., positions {0, 2, 4}.

However, after reading the docs I only found the function ArrayBSearch( ), which can only be used to find numeric values in an array.

Is there any way in MQL5 to perform such task?

Thanks in advance! 

 
Malacarne:

Suppose I have an array called StringArray[ ] filled with five string values like shown below:

I want to search this array for all string values starting with "ABC".

The desired answer would be the position of these elements in the array, i.e., positions {0, 2, 4}.

However, after reading the docs I only found the function ArrayBSearch( ), which can only be used to find numeric values in an array.

Is there any way in MQL5 to perform such task?

Thanks in advance! 

You'd have to use a for loop...
 

You can either use a loop for each element of your array, and use the function StringFind()

Or you can use the class CArrayString from the Standard Library, probably with on of the method SearchXXX.

 

Thanks for the comments...

The solution I've implemented is shown below:

   for(int i=0;i<ArraySize(StringArray);i++)
     {
      if(StringFind(StringArray[i],"ABC") != -1)
        {
         Print("Position "+i+" = "+StringArray[i]);
        }
     }