Sending byte by byte char array with undefined number of bytes

Hello,
I am trying to build function that sends char array with values dependant on numbers I read from sensors to other arduino board. I receive from sensor number from 2 to lets say 20 digits and I want to send only those digits I read from sensor.

Lets say variable is "Char Varr[20];" and it has from 2 to 20 digits rest are zeros.

I use function
WifiSend(Varr);

Transmitter:

void WifiSend(char Xbuffer[]){


for (i = 0; i < 20; i++){
    Xbuffer[i]=Xbuffer[i];
    Serial.print(Xbuffer[i]);
   
}




  [color=red]  if (!wirelessSPI.write(Xbuffer, [b]20[/b])) {[/color]
      //if the send fails let the user know over serial monitor
      Serial.println("packet delivery failed");
    }
 

 
        for(i=0;i<20;i++){
          Xbuffer[i]=0;
         }
    
      
}

Receiver:

 if(wirelessSPI.available()){ 
                  
        wirelessSPI.read( Ybuffer, 20); //read one byte of data and store it in Ybuffer variable
         
      
          char cArray[10] = "done_man"; //create char array to store "done," note that the fifth char is for the null character
          wirelessSPI.writeAckPayload(1, cArray, sizeof(cArray));  //send ack payload. First argument is pipe number, then pointer to variable, then variable size
          Serial.println("");
          Serial.print("Recieved packet: "); 
          for(int i=0; i<Ybuffer[0]+1; i++){   
            Serial.print(Ybuffer[i]);
          }
          Serial.println("");
         

          
         [b] for(int i=0; i<20; i++){
          Ybuffer[i]=0;[/b]
          }
    
      }

The question is there any way to determine correct number of bytes I am sending? Or at least making results printed without trash:

Usually you would send one byte with the number of bytes following it, like this:

char data[20];
byte dataUsed;

void send() {
  write(dataUsed);
  for (int i = 0; i < dataUsed; i++) write(data[i]);
}

void receive() {
  dataUsed = read();
  for (int i = 0; i < dataUsed; i++) data[i] = read();
}

It looks like you have text. In which case you can add a terminating null character after the received sensor data and send till the character in the buffer is '\0'.

Adding that terminator to trasmiter and searrching for it in receiver code:

while (i<20){   
              if(Ybuffer[i]!='/'){
              Ybuffer[i]=Ybuffer[i];
              Serial.print(Ybuffer[i]);
              i++;
              }
              else{
              i++;
              break;
              Serial.println("");
              }            
          }

worked thank you.

I am still sending trash because I probably would have to first send number of bytes as 1 byte, and than put this number in here:

 wirelessSPI.read( Ybuffer, 20);

maybe I will think about it later for now it is good to see it working at least.

Below a slightly modified version. It checks if the character is the null terminator.

I've also commented out two useless lines. The first one did not do anything (basically copying a to a). The second one would never be executed because it's after the break.

while (Ybuffer[i] != '\0'){   
  if(Ybuffer[i]!='/'){
    //Ybuffer[i]=Ybuffer[i];
    Serial.print(Ybuffer[i]);
    i++;
    }
    else{
      i++;
      break;
      //Serial.println("");
    }
}
]/code]