Questions from a "dummy" - page 34

 

About StringSplit: why can't I use a static array?

Example from the help

string to_split="мама_мыла_раму"; // строка для разбивки на подстроки
   string sep="_";                // раздедитель в виде символа
   ushort u_sep;                  // код символа разделителя
   string result[3];               // массив для получения строк
   //--- получим код разделителя
   u_sep=StringGetCharacter(sep,0);
   //--- разобьем строку на подстроки
   int k=StringSplit(to_split,u_sep,result);
   //--- выведем комментарий 
   PrintFormat("Получено строк: %d. Использован разделитель '%s' с кодом %d",k,sep,u_sep);
   //--- теперь выведем все полученные строки
   if(k>0)
     {
      for(int i=0;i<k;i++)
        {
         PrintFormat("result[%d]=%s",i,result[i]);
        }
     }
It works, but it generates error 4007. It looks like there should be enough memory and no need to change the size... I don't understand.
 
Silent:

About StringSplit: why can't I use a static array?

Example from the help file

It works, but it generates error 4007. It seems to be enough memory and it doesn't need to be resized... I don't understand.
case 4007: error_string="Недостаточно памяти для перераспределения массива либо попытка изменения размера статического массива!";
Does the helper also say "mother washed the frame"? If you're referring to an example from the help, give us a link to the example as well.
 
tol64:
Does the help say "mum washed the frame" too? If you're referring to an example from the help, give us a link to the example as well.

You won't believe it...

 
Silent:

You won't believe it...

There is no such thing as an array declared string result[3]; There is an error in the link, because:

"Not enough memory to redistribute the array or an attempt to resize the static array!"

 
tol64:
There is no such thing as an array declared string result[3]; There is an error in this.
I asked why, and highlighted where (changed).
 
Silent:
I asked - why, and highlighted - where (changed).
Because you declared the array to be static - 3. And the resulting substring has more than 3 characters.
Документация по MQL5: Основы языка / Переменные
Документация по MQL5: Основы языка / Переменные
  • www.mql5.com
Основы языка / Переменные - Документация по MQL5
 
Silent:
I asked why, and highlighted where (changed).
It is not clear with static arrays in general, when and how to apply them. It seems that I don't want to leave the compiler to its mercy, and I don't want to encounter such problems - it seems to work, but there are errors.
 
tol64:
Because you declared the array to be static - 3. And the resulting substring has more than 3 characters.
Static [3] is 3 (sub)strings, not 3 characters, I thought.
 
Silent:
Static [3] is 3 (sub)lines, not 3 characters, I thought.

Yes, if you remove up to 3 letters

2011.07.28 00:43:55     StringSplit (EURUSD,H1) _LastError 1 4007
2011.07.28 00:43:55     StringSplit (EURUSD,H1) result[2]=рам
2011.07.28 00:43:55     StringSplit (EURUSD,H1) result[1]=мыл
2011.07.28 00:43:55     StringSplit (EURUSD,H1) result[0]=мам
2011.07.28 00:43:55     StringSplit (EURUSD,H1) Получено строк: 3. Использован разделитель '_' с кодом 95
that's not the point.
 
Silent:
It is not clear with static arrays in general, when and how to use them. It seems that I don't want to leave the compiler to its mercy, and I don't want to encounter such problems - it seems to work, but there are errors.
And you try to study this or that subject when you need it. As soon as you reach the point in your system when you need these or those "levers" (functions), then start experimenting with them. I've found that this method of learning (in my case) works quite well.))
Reason: