Download MetaTrader 5
To add comments, please log in or register
Have you developed a trading robot? Publish it in the Market and make profit!
Pierre
25
Pierre 2015.01.29 15:27 

Hi

  I try to adapt and customize a code and I still have three errors Quye I can not seem to correct, the block of code in question :

 //+------------------------------------------------------------------+

//|add char at beginning or end of text                              |

//+------------------------------------------------------------------+

string addStr(string str, string char, int maxlength, bool atbeginning = true)

{

   int l = maxlength - StringLen(str);

   for (int i=0; i<l; i++)

   {

      if (atbeginning) str = char + str;

      else str = str + char;

   }

     

   return(str);

} 


 

 and the errors detected :

 

'char' - unexpected token

'+' - unexpected token

';' - unexpected token

 

Thanks 

David Mkheidze
183
David Mkheidze 2015.01.29 15:44  

Hi,

 

char is the type in MQL so its a keyword and cannot be used as the name of a parameter. Try something different like character. 

 

So your code becomes:

  

string addStr(string str, string character, int maxlength, bool atbeginning = true)

{

   int l = maxlength - StringLen(str);

   for (int i=0; i<l; i++)

   {

      if (atbeginning) str = character + str;

      else str = str + character;

   }

     

   return(str);

} 
Alain Verleyen
Moderator
28518
Alain Verleyen 2015.01.29 15:45  

Hello,

Please use the SRC button when you post code. Thank you.


This time, I edited it for you.

Pierre
25
Pierre 2015.01.29 16:19  

mkheidzedavid

Wonderful, That's great, thank you a thousand , I guard the lesson for my next encoding tests

 

Sorry angevoyageur, the next time I 'll do it. 

/
To add comments, please log in or register