Please help me : Error in code

 

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 

 

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);

} 
 

Hello,

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


This time, I edited it for you.

 

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. 

Reason: