how delete some record in array ?

 

Hi guy   i have  one array  with 10 record   but  the  first  and   last  is  empty  i want remove this record how  possible to do that ?

i have crete this  code  but  return array  overflow  therefore  i think  i have  some mistake

void _CleanArrayIFsomeEmpty(string& Arry[])
{
   string newSymbols[]; // Il nuovo array senza elementi vuoti
   int newSize = 0; // La nuova dimensione dell'array

   // Scorrere l'array e copiare solo gli elementi non vuoti nel nuovo array
   for (int i = 0; i < ArraySize(Arry); i++)
   {
       if (StringLen(Arry[i]) > 0)
       {
           newSymbols[newSize++] = Arry[i];
       }
   }
   
   // Ora newSymbols[] contiene solo gli elementi non vuoti
   ArrayResize(Arry, newSize); // Ridimensiona l'array originale alla nuova dimensione
   for (int Ni = 0; Ni < newSize; Ni++)
   {
       Arry[Ni] = newSymbols[Ni]; // Copia gli elementi non vuoti nell'array originale
   }
}
anyone  can help me ?? thanks 
 
faustfi have crete this  code  but  return array  overflow 
  1. Of course, it does. Your newSymbols[] is empty; zero size.
  2. It is unnecessary.
    void _CleanArrayIFsomeEmpty(string& Arry[])
    {
        ArrayResize(array, remove_copy(Arry, 0, ArraySize(Arry), Arry, 0, "") );
    }
    #define INDEX uint
    template<typename Ti, typename To>
    INDEX                remove_copy(const Ti& inp[], INDEX iBeg, INDEX iEnd,
                                           To& out[], INDEX oBeg, const Ti& value){
       for(; iBeg != iEnd; ++iBeg){
          if(!(inp[iBeg] == value) )             out[oBeg++] = inp[iBeg];
       }
       return oBeg;
    }
    

 

thanks  for rply but not understund  your code  , i try to test  your  code  but return many error

'array' - undeclared identifier common_functions.mqh    2088    17
'' - parameter passed as reference, variable expected   common_functions.mqh    2088    71
'' - parameter passed as reference, variable expected   common_functions.mqh    2088    71
'' - parameter passed as reference, variable expected   common_functions.mqh    2088    71
'array' - parameter conversion not allowed      common_functions.mqh    2088    17
'array' - array required        common_functions.mqh    2088    17
 
faustf #:

thanks  for rply but not understund  your code  , i try to test  your  code  but return many error

i correct the code  in this mode  and now  go


void _CleanArrayIFsomeEmpty(string& Arry[])
{
const string de="";
    ArrayResize(Arry, remove_copy(Arry, 0, ArraySize(Arry), Arry, 0, de) );
}

#define INDEX int

template<typename Ti, typename To>
INDEX remove_copy(const Ti& inp[], INDEX iBeg, INDEX iEnd,
                 To& out[], INDEX oBeg, const Ti& value)
{
    for (; iBeg != iEnd; ++iBeg)
    {
        if (!(inp[iBeg] == value))
            out[oBeg++] = inp[iBeg];
    }
    return oBeg;
}

thanks  so much @William Roeder
 

sorry if i resurected this topic, but i notice the function not work, remaning a blank record

i have array with 10 record , the first and the last is blank(but could be at middle), i want remove the blank record and transform array in size in 8 (and the second record will be a first )

how is possible to do that ???

 
faustf #:

sorry if i resurected this topic , but i notice the function not work , remaning a blank record

i have array with 10 record , the first and the last is blank(but could be at middle), i want remove the blank record and transform array in size in 8 (and the second record will be a first )

how is possible to do that ???

What do you mean “blank”?
 
Daniel Cioca #: What do you mean “blank”?

empty, with not  data  inside

 
faustf #: empty, with not  data  inside
Show an example of your code, the function provided does what it is supposed to do. I would guess, there is an error in your code.
 
Dominik Egert #:
Show an example of your code, the function provided does what it is supposed to do. I would guess, there is an error in your code.

i write  up

void _CleanArrayIFsomeEmpty(string& Arry[])
{
const string de="";
Print("cane di pio nono "+ ArraySize(Arry));
    ArrayResize(Arry, remove_copy(Arry, 0, ArraySize(Arry), Arry, 0, de) );
    Print("cane di gesu morto  "+ ArraySize(Arry));
}

#define INDEX int

template<typename Ti, typename To>
INDEX remove_copy(const Ti& inp[], INDEX iBeg, INDEX iEnd,
                 To& out[], INDEX oBeg, const Ti& value)
{
    for (; iBeg != iEnd; ++iBeg)
    {
        if (!(inp[iBeg] == value))
            out[oBeg++] = inp[iBeg];
           //  Print ("cane di dio---->" +inp[iBeg]);
    }
    return oBeg;
}
 
faustf #:

i write  up

Sample data?
Print out of journal?
Translation of your text?

Do you expect me to do that all for you, so you get a working code??

Please provide so that I am able to reproduce, without guessing.
 

i  tried  also in this mode but  nothing, return 12 :(((((

// Funzione per rimuovere i record vuoti da un array di stringhe
void RemoveEmptyRecords(string &array[]) {
    string newArray[];
    int newSize = 0;

    for (int i = 0; i < ArraySize(array); i++) {
        if (StringLen(array[i]) > 0) {
            ArrayResize(newArray, newSize + 1);
            newArray[newSize] = array[i];
            newSize++;
        }
    }

    ArrayCopy(array, newArray);
}



// Esempio di utilizzo della funzione
void OnStart() {
    string myArray[] = {"", "AUDUSD", "AUDJPY", "", "NZDJPY", "AUDJPY", "GBPAUD", "EURUSD", "EURAUD", "EURGBP", "EURUSD", ""};
    RemoveEmptyRecords(myArray);
    Print("Array senza record vuoti: ", ArraySize(myArray));
}

 i try also in this mode  but  arraCpy not  copy  :(((

// Funzione per rimuovere i record vuoti da un array di stringhe
void RemoveEmptyRecords(string &array[]) {
    string newArray[];
    
    for (int i = 0; i < ArraySize(array); i++) {
        if (StringLen(array[i]) > 0) {
            ArrayResize(newArray, ArraySize(newArray) + 1);
            newArray[ArraySize(newArray) - 1] = array[i];
        }
    }
    ArrayFree(array);
     ArrayResize(array,ArraySize(newArray),ArraySize(newArray)); 
    
    ArrayCopy(newArray, array);
}
Reason: