[...]
I'd guess the following:
- When processing the parameters for Alert(), MT4 evaluates the StringReplace() before the StringFind()
- StringReplace() modifies the s variable (i.e. modifies in place, rather than returning the modified string)
- So, StringFind() is called after StringReplace() has been called, and therefore after the \n characters have been replaced with spaces
- Therefore, StringFind() says that there are no \n characters in the string
I'd guess the following:
- When processing the parameters for Alert(), MT4 evaluates the StringReplace() before the StringFind()
- StringReplace() modifies the s variable (i.e. modifies in place, rather than returning the modified string)
- So, StringFind() is called after StringReplace() has been called, and therefore after the \n characters have been replaced with spaces
- Therefore, StringFind() says that there are no \n characters in the string
hmmm I wrote Alert code to two rows:
Alert (StringFind(s,"\n",0)); // return: 0 Alert(StringReplace(s,"\n"," ") ); // return: 3
strange behavior MT4 (for me)
The order that parameters are processed is not defined. Therefor your original alert did the replace first, creating a new s. Then the find proceeded, on the no longer existing string.
hmmm I wrote Alert code to two rows:
strange behavior MT4 (for me)
Once again, the MQL manual has a rather strange approach in expressing "notions". The expression int b=(a++)*3 is not invalid, as if invalid means that it will generate a compilation error.
All in all , it will work as described in that very page
" The prefix increment (++i) and decrement (--k) are applied to the variable right before this variable is used in an expression.
Post-increment (a++) and post-decrement (k--) are applied to the variable right after this variable is used in an expression"
As an example, the following part is working as expected
int a=5; int b=(a++)*5; int c=(++a)*5; Alert(a," ",b," ",c);
Regarding OP's question, it looks like there is a "bug". I put double quotes on it because it seems that the functions are regarded as "imported"; as such they are, as have been said, evaluated form right to left. Still, please pay attention to the manual saying regarding StringFind()
"Return Value
Returns position number in a string, from which the searched substring starts, or -1, if the substring is not found"
As such, it is legitimate to return 0
EDIT at the manual, at page Functions > Function call, we can read
" The order of expressions calculation and the order of values loading are not guaranteed "
I guess that statement is above and beyond any rules regarding precedence rules hehe
best regarsds
Demos:
All in all , it will work as described in that very page
" The prefix increment (++i) and decrement (--k) are applied to the variable right before this variable is used in an expression.
Post-increment (a++) and post-decrement (k--) are applied to the variable right after this variable is used in an expression"
" The order of expressions calculation and the order of values loading are not guaranteed "

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
return: StringFind() --> -1
StringReplace() --> 3