StringConcatenate in MQL5 versus MQL4

Hi,

I’m porting my mq4 program to mq5 and I face compilation issues, not sure what variable expected here as I’m already passing str variable for StringSubst.

   const string str=NewsArr[0][nomf];

   string time=StringConcatenate(StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));


Error:

'StringSubstr' - variable expected   

Pls help

Is this an indicator with code in OnCalculate where you have a parameter named time ?

It does not work when you use it within the StringConcatenate() function

Use it like this instead

   string time=StringSubstr(str,0,4)+"."+StringSubstr(str,5,2)+"."+StringSubstr(str,8,2)+" "+StringSubstr(str,11,2)+":"+StringSubstr(str,14,4);  

Yes it works with StringConcatenate(), but the mql5 version of this function is not the same as mql4.

   string time;
   StringConcatenate(time,StringSubstr (str,0,4),".",StringSubstr(str,5,2),".",StringSubstr(str,8,2)," ",StringSubstr(str,11,2),":",StringSubstr(str,14,4));  

Yep. My bad ;(

Thanks :slight_smile:

Awesome!!!

Thanks bstaddart0 It worked

Yes, but read this post too :

So it works within string concatenate too (if the first parameter is not omitted and is properly declared as variable)

It depends what form do you like more. I don’t like StringConcatenate() (which is obvious:)) and I prefer using the + form (less code and simpler to follow) - but that depends on the style I guess

Hi,
I’m trying to do the same thing and I am facing a different error.

I added the url specified at this link but I’m getting this error.
image__39
image__40
Any idea why?

Best Regards

string time = StringSubstr (str,0,4) + "." +
	          StringSubstr(str,5,2)  + "." +
              StringSubstr(str,8,2)  + " " +
              StringSubstr(str,11,2) + ":" +
    	      StringSubstr(str,14,4));
1 Like

thanks @mql5com that helped