Please help me : Error in code

Back to topics list To post a new topic, please log in or register
avatar
8
Recon004 2015.01.29 16: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 

 

avatar
59
mkheidzedavid 2015.01.29 16: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);

} 
avatar
Moderator
3206
angevoyageur 2015.01.29 16:45 #
 

Hello,

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


This time, I edited it for you.

avatar
8
Recon004 2015.01.29 17: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. 

Back to topics list  

To add comments, please log in or register