How to find maximum number in string array

 

i have a string array 

string w_[];
//values are ..
w_1
w_2
w_3
....
w_50

I want to find string which has maximum index e.g. in this case w_50

How can i do it

 
You could take a look at StringFind, StringLen and StringSubstr in documentation string functions. 

Then figure out a way to extract the number from the string so you can compare them and keep the
index of the highest number.

If you have questions about this write back.
 
Arpit T:

i have a string array
I want to find string which has maximum index e.g. in this case w_50
How can i do it

Hello,

You can find the largest or lowest value by sorting the contents of the array.
https://docs.mql4.com/array/arraysort

Since the contents of your array are strings, the numbers must be in the following format:

w_01
w_02
w_03
...
w_50
ArraySort - Array Functions - MQL4 Reference
ArraySort - Array Functions - MQL4 Reference
  • docs.mql4.com
ArraySort - Array Functions - MQL4 Reference
 

There are no numbers in a string. ("_10" comes before "_9", etc.)

Isolate the number part, convert it to a number, and store them in a numeric array.

Now you can search that and get the index for both.
          Sort orders based on OrderOpenTime MQL4 programming forum (2020)

Reason: