print the collected characters in one line as a string

i use slave receiver code ,i want to turn incoming characters to one string …i Succeeded to do that but the string wont print in one line …how can i print my string in one line … thanks in advance.
this is the code :

#include <Wire.h>
void setup()
{
Wire.begin(4); // join i2c bus with address #4
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600); // start serial for output
}

void loop()
{
delay(100);
}
void receiveEvent(int howMany)
{
while (1 < Wire.available())
{
char c = Wire.read();
String string="";
string+=char(c);
//String string=“xis”;
Serial.println(string);
delay(300);
}
int x = Wire.read();
}

 while (1 < Wire.available())
  {
    char c = Wire.read(); 
   String string="";
  string+=char(c);
  //String string="xis";
  Serial.println(string);
delay(300);
  }

Since the declaration of String string is inside the while loop, it goes out of scope and is destroyed each time the while loop exits and re-enters. So for each character you are creating a brand new String for just one character. Then you call Serial.println regardless of whether or not you have reached the end of the input.

If you used Serial.print instead of println, it would put them all on the same line together, but I don’t think that is what you want.

The first thing you need to do is forget you ever heard of the String class. It isn’t appropriate for microcontrollers anyway. Then go look at the Serial Input Basics thread. It will show how to collect your characters until your transmission is finished and then print them.

@fuhrer94: Welcome to the Forum. To help us help you, please read the posting guidelines by Nick Gammon at the top of this Forum.

@Delta-G:

Since the declaration of String string is inside the while loop...

That is not a declaration, it is a definition. The two terms are not the same. Also, I agree with the suggestion of the OP dumping the String class...too much code bloat for what you get.