Add character to string

Hello,

I would like to add a character to a string. I tryied this:

  char datarcv;
  String content = "";
  while(Serial3.available())
  {
    datarcv = Serial3.read();
    content.concat(datarcv);
    Serial.println(content);
  }

But It display this (I send: test):

t
e
s
t

How resolve this ?

regards

I would like to add a character to a string.

But, you don't have a string. You have a String. Not the same thing at all.

But It display this (I send: test):

Why do you expect something else? Serial data arrives sssslllloooowwwwllllyyyy. On every pass through loop, you reset the String to nothing, so it never holds more than one character.

FindL: How resolve this ?

You'd better consider: - the while-loop is running several thousand times per second - Serial is slow, at 9600 baud only one character per millisecond arrives

So if the posted code is within your loop() function (don't know about?), each time the while-loop begins, it finds none or one character in the Serial input buffer, but never more than one.

In a crappy code using string-objects instead of real C-strings, you could make the code even crappier (but working like intended) using "delay" to wait a little bit after the first character had been received:

 char datarcv;
  String content = "";
  if (Serial3.available()) // now we have at least one character in the Serial input buffer
  {
    delay(20); // just wait a little bit for more characters to arrive
    while(Serial3.available()) // look for all characters in the input buffer
    {
      datarcv = Serial3.read();
      content.concat(datarcv);
    }
    Serial.println(content); // and print them all together
  }