According to the description of these functions in MQL5 Reference, they allow us to add up strings in a more space efficient (in terms of the occupied working memory) and faster way.
De hecho hay incoherencias en la documentación. No sé sobre el uso de memoria, pero sobre si es más rápido o no, StringConcatenate() es MUCHO más lento que StringAdd y +.
2013.04.11 19:09:48 teststring (EURUSD,M1) time for 'StringConcatenate(c,a,b)' = 1170 milliseconds, i = 1000000 2013.04.11 19:09:47 teststring (EURUSD,M1) time for 'StringAdd(a,b)' = 94 milliseconds, i = 1000000 2013.04.11 19:09:47 teststring (EURUSD,M1) time for 'c = a + b' = 265 milliseconds, i = 1000000
Buen artículo, imprescindible para todos los principiantes.
Añade un separador de grupo de dígitos a la cadena:
//+------------------------------------------------------------------+//|DelimiterGroupsDigits.mq5//| Copyright 2018, MetaQuotes Software Corp. | |//| https://www.mql5.com//+------------------------------------------------------------------+#property script_show_inputs//--- Parámetros externosinputdouble Value =1000000;
inputstring Delimiter =" "; // Delimitador, por defecto: " ", ejemplo: 1 000 000.0//+------------------------------------------------------------------+//| Función de inicio del programa de script|//+------------------------------------------------------------------+voidOnStart(void)
{
::Print(DelimiterGroupsDigits(string(Value),Delimiter));
}
//+------------------------------------------------------------------+//| Separador de grupos de dígitos|//+------------------------------------------------------------------+string DelimiterGroupsDigits(conststring value,conststring delimiter=" ")
{
string res=value;
string elements[];
//--- Elimina los caracteres extra de los bordes.
::StringTrimLeft(res);
::StringTrimRight(res);
//--- Comprueba si es un número realushort sep =::StringGetCharacter(".",0);
int total =::StringSplit(res,sep,elements);
//--- Tengo la cadenaif(total>0)
{
string str[];
int length=::StringLen(elements[0]);
for(int k=0,i=length-1; i>=0; i--)
{
int size=::ArraySize(str);
::ArrayResize(str,size+1);
str[size]=::StringSubstr(elements[0],i,1);
k++;
//--- Añade un separadorif(k>=3 && i>0)
{
int array_size=::ArraySize(str);
::ArrayResize(str,array_size+1);
str[array_size]=delimiter;
k=0;
}
}
//--- Recoge la cadena
res="";
int elements_total=::ArraySize(str);
for(int i=elements_total-1; i>=0; i--)
::StringAdd(res,str[i]);
//--- Si es un número realif(total>1)
::StringAdd(res,"."+elements[1]);
}
//--- Devuelve el resultadoreturn(res);
}
//+------------------------------------------------------------------+
Para iniciar sesión y usar el sitio web MQL5.com es necesario permitir el uso de Сookies.
Por favor, active este ajuste en su navegador, de lo contrario, no podrá iniciar sesión.
Ha iniciado sesión. La autenticación de dos factores se ha desactivado. Vuelva a configurarla y escanee un nuevo código QR, o continúe con la autenticación de dos factores desactivada.
...Personalmente, me interesaba la pregunta sobre las limitaciones de longitud de línea....
According to the description of these functions in MQL5 Reference, they allow us to add up strings in a more space efficient (in terms of the occupied working memory) and faster way.
De hecho hay incoherencias en la documentación. No sé sobre el uso de memoria, pero sobre si es más rápido o no, StringConcatenate() es MUCHO más lento que StringAdd y +.
2013.04.11 19:09:48 teststring (EURUSD,M1) time for 'StringConcatenate(c,a,b)' = 1170 milliseconds, i = 1000000
2013.04.11 19:09:47 teststring (EURUSD,M1) time for 'StringAdd(a,b)' = 94 milliseconds, i = 1000000
2013.04.11 19:09:47 teststring (EURUSD,M1) time for 'c = a + b' = 265 milliseconds, i = 1000000
Buen artículo, imprescindible para todos los principiantes.
es agradable cansarte para hacernos menos ignorantes. gracias por tu trabajo
Añade un separador de grupo de dígitos a la cadena:
//---
Resultado:
Añade un separador de grupos de dígitos a una cadena:
Es un poco complicado.
¿Intentará optimizarlo?
¡Estupendo! Y cuatro veces más rápido:
//---