string size in mql5

 

Hi

how many characters a string can have in mql5?

 
farhadmax:

Hi

how many characters a string can have in mql5?

The exact limit I am not sure, it's below 4800.

I use 3500 to cut my strings, at least for printf().

If I need more, I use (unsigned) short or char arrays. Alternatively I use string arrays for individual lines, if I want to feed them to printf().



EDIT: The actual limit is not below 4800, as I was remembering wrong, it is actually 16381 chars that printf() or Print() function will print in  a single call to expert-journal.

Proof, see below.

 
   
   #property script_show_inputs

   string longText;

   void OnStart() {

   appentToText ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
   appentToText ("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb");
   appentToText ("ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc");
   appentToText ("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
   appentToText ("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
   appentToText ("fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
   appentToText ("iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii");
   appentToText ("jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj");
   appentToText ("===================================================================");
   
   Print("longText lengh is: " + longText.Length());
   Print(longText);

   }
   
   
   void appentToText ( string txt) {
      string temp;
      StringConcatenate(temp, longText , txt);
      longText = temp;
   }
   

I have written this code. It prints only 603 characters on terminal output.  (longText lengh is: 603)

why it doesn't print all characters?

 
Dominik Christian Egert #:
The exact limit I am not sure, it's below 4800.

I use 3500 to cut my strings, at least for printf().

If I need more, I use (unsigned) short or char arrays. Alternatively I use string arrays for individual lines, if I want to feed them to printf().



Why are you thinking it's below 4800 ?

I have here a string of 65,966 characters. It's from one of my project, I didn't check what the limit could be.


 
Alain Verleyen #:

Why are you thinking it's below 4800 ?

I have here a string of 65,966 characters. It's from one of my project, I didn't check what the limit could be.


Not the variable itself, but what printf is processing from the variable. - Same goes for StringFormat, I reported this to MQ, and I think StringF is fixed, though I never came back to check, since it never had been an issue to me again.

As I described, I solved it by using arrays of type string and calling printf multiple times, for each line.

I never checked the limits of the variable string type, I only encounterd issues with printf and stringf.





 
Alain Verleyen #:

Why are you thinking it's below 4800 ?

I have here a string of 65,966 characters. It's from one of my project, I didn't check what the limit could be.


I have tested the limit of printf and Print function, here is the script to reproduce. 

Result: Max printable string-len using either is 16382 characters in a string.

static string test = NULL;
//+------------------------------------------------------------------+
//| Service program start function                                   |
//+------------------------------------------------------------------+
void OnStart()
{
    // printf string limit is 16382 chars
    // Print string limit is 16382 chars.

    StringInit(test, 16350, 0x0040);
    int alpha = StringLen(test);
    while( (StringLen(test) == alpha)
        && (alpha < 16390)
        && (!_StopFlag) )
    {
        test += CharToString((char)((alpha%(96 - 65)) + 65));
        Print(test);
        Print("Size: ", StringLen(test));
        alpha++;
    }

    StringInit(test, 16350, 0x0040);
    alpha = StringLen(test);
    while( (StringLen(test) == alpha)
        && (alpha < 16390)
        && (!_StopFlag) )
    {
        test += CharToString((char)((alpha%(96 - 65)) + 65));
        printf("%s", test);
        printf("Size: %i", StringLen(test));
        alpha++;
    }

    return;

}
 
Dominik Christian Egert #:

I have tested the limit of printf and Print function, here is the script to reproduce. 

Result: Max printable string-len using either is 16381 characters in a string.


Ok but the topic was not about printf or Print.

I am getting a limit of 16364 (I moved the start of the line at the end to better show it).


 
Alain Verleyen #:

Ok but the topic was not about printf or Print.

I am getting a limit of 16364 (I moved the start of the line at the end to better show it).


You are right, the previous result was wrong.


I updated the code listing above, and the result to reflect the actual readings... 

Reason: