Reading multiple bytes from a server and putting them into a string

I'm trying to parse out a message received from a sever where the Arduino is the client. The message consists of numbers and letters and is split based on spaces and ";" - such as "s112; 223; set; 32s ". When I run my code and the server send the message it prints a few blank lines and that is it. I have tried by assigning the string to Msg and it printed out as I expected. I think I am having trouble where I convert char serverMsg =; to String Msg = String(serverMsg); as I think it only reads one character at a time that way and I am unsure of going about it any other way.

Here' the code!

if (client.available()) {
char serverMsg =;
String Msg = String(serverMsg);
String parsedMsg[50];
int r = 0, t = 0;

for (int i = 0; i < Msg.length(); i++)
  if (Msg[i] == ' ' || Msg[i] == ';')
    if (i - r > 1)
      parsedMsg[t] = Msg.substring(r, i);
    r = (i + 1);
for (int k = 0; k <= t; k++)


if you really want to use a String you could have a global variable for the message

String message;

that you initialise in the setup()

void setup() {
  message = "";

and where you get the answer from the server, you build up your message based on what you get back.

while (client.available()) message.concat((char);

then you can use the String class methods to clean up and parse what you got. Don't forget to empty the string with a message = ""; once you are done so that you don't keep the content for next round.

(using a char buffer would be better in terms of memory management)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.