StringSubstr(input,startpos) copies only first 4096 bytes

 

I noticed while working with long strings that long strings are ok but function StringSubstr(input,starpos) copies only first 4096 bytes of the input string.

This bug could be fixed in the next build if they still make new builds in mql4.

 

4096 is more than promised, therefore its no bug, its a feature ;-)

The length of a string constant lies between 0 and 255 characters.

If the string constant is longer, the superfluous characters on the right will be rejected, and compiler will alert correspondingly.

 

This is actually not true. I was working on a script to create a special version of detialed statement similar to the one created in MT4 as html file, and created a string of more than 260,000 bytes by concatenating many smaller strings into one which I then write to an html file. Even those smaller strings were more than 255 bytes.

Here is more definition from string:

Its internal representation is a structure of 8 bytes. The first element of the structure is a long integer that contains the size of the buffer distributed for the line. The second element of the structure is 32-order address of the buffer that contains the line.

So the first length element should allow string to be up to 2GB in length.

But when using substring it only copies first 4096 bytes or so which is strange and is kind of an arbitrary number.

In any case 255 length limitation is kind of silly nowadays, as it had been dropped since the early 80s - the infancy of personal computers.

 

my post was copied from the doc mql4, not my genius idea ....

 

The documentation states that A string constant is an array of characters enclosed in quotes... The length of a string constant lies between 0 and 255 characters.

A string variable is not the same as a string constant.


irusoh1, did u ever concatenate a string up to 2gb to verify?

 
gordon:

irusoh1, did u ever concatenate a string up to 2gb to verify?

Personally, I can't replicate any problems with StringSubstr() using code such as the following:


   // Build 32,768 byte string 
   string x = "01234567";
   for (int i = 0; i < 12; i++) {
      x = StringConcatenate(x, x);
   }
   
   // Take a copy of the string using Substr(string, 0)
   string y = StringSubstr(x, 0);
   
   // Show comparative lengths
   MessageBox("Original: " + StringLen(x) + " bytes\r\nCopy: " + StringLen(y) + " bytes");


However, I have seen strange issues with what looks like a 4096-character buffer or limit when writing long strings to files using FileWriteString() and then reading them back using FileReadString()...

Reason: