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 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]); } }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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!