Difference (string) and StringConcatenate?

 

Hi all!

I have an EA that I sourced some additional code after the developer delivered it to me, and I've have ended up with two different ways to create strings:

string comment=StringConcatenate("Today's Profit Target: $", DoubleToStr(GlobalVariableGet(gDailyProfitTarget), 2));

string gDailyProfitTarget = (string)ChartID() + "8595" + "DPT";

What's the difference between these methods? I can't find the latter in documentation thus far.

 
Semi-relatedly, what is the difference between DoubleToStr and DoubleTo String? They look exactly the same to me.
 
rrsch #: Semi-relatedly, what is the difference between DoubleToStr and DoubleTo String? They look exactly the same to me.
DoubleToStr is the old MQL4 function, while DoubleToString is the newer MQL4+/MQL5 function for compatibility with both platforms.
 
rrsch: I have an EA that I sourced some additional code after the developer delivered it to me, and I've have ended up with two different ways to create strings: What's the difference between these methods? I can't find the latter in documentation thus far.

Both are similar but are accomplished in different ways. There was a time where StringConcatenate allowed for a longer resulting string and the "+" method did not. Then there was another time where it was the opposite. Currently however, I believe both have the same maximum resulting length.

As for speed or memory efficiency, I do not know which is best. One would have to measure it to see which would be faster or consume less memory.

 
Fernando Carreiro #:

Both are similar but are accomplished in different ways. There was a time where StringConcatenate allowed for a longer resulting string and the "+" method did not. Then there was another time where it was the opposite. Currently however, I believe both have the same maximum resulting length.

As for speed or memory efficiency, I do not know which is best. One would have to measure it to see which would be faster or consume less memory.

Thanks!

Is (qstring) a function? The syntax doesn’t match all the other functions I’ve seen, where normally the content I want to do something with goes in between the parentheses, not afterward. 
 
rrsch #Is (qstring) a function? The syntax doesn’t match all the other functions I’ve seen, where normally the content I want to do something with goes in between the parentheses, not afterward. 

No, "(string)" is data-type type-casting, but it can be written to look like a function ...

string text = (string) number;  // type-casting in the "c/c++" style
string text = string( number ); // type-casting in MQL style, that looks like a function
Typecasting - Data Types - Language Basics - MQL4 Reference
Typecasting - Data Types - Language Basics - MQL4 Reference
  • docs.mql4.com
Typecasting - Data Types - Language Basics - MQL4 Reference
Reason: