storing data from a telnet server to x number of variables.

I need help, hopefully just a push in the correct direction.

I have written a simple sketch that connect to a telnet server.

The server responds with some information I need to capture and store for use later.

Below is an example of what the server sends me.

RL3]\[Test 1}|{3}|{S]\[Test 2}|{41}|{L]\[Test 3}|{1234}|{L

The RL shows that this line is a Roster List, the number after is how many items in this list.

I have the code that can read through the message and identifies when the roster lists begins and I read the number into an integer.

What I need is to be able to save the data to however many variables I need. The amount in the roster list will vary.

From the example above i need the following: -

Test 1, 3, S
Test2, 41, L
Test 3, 1234, L

This is what I have so far.

void read() {
  
String content = "";
  char character;

  while(client.available()) {
      character = client.read();
      if (character == 'R') {
        character = client.read();
        if (character == 'L') {

          //We are in the roster list section
          Serial.println("Roster list seen");
          roster = client.parseInt();  //sets how many items in roster

        } 
      }
      content.concat(character);
  }


}

Any help appreciated.

Thanks.

you could use the string tokeniser strtok() to break the string into tokens, e.g.

// strtok example - parse tokens

void setup() {
  // put your setup code here, to run once:
    Serial.begin(115200);
    char str[] ="RL3]\[Test 1}|{3}|{S]\[Test 2}|{41}|{L]\[Test 3}|{1234}|{L";    // text to tokenise
    char * pch;                     // pointer to tokens
    Serial.print("Splitting string ");
    Serial.print(str);
    Serial.println(" into tokens:");
    pch = strtok (str,"}]\[|{");         // get first token
    while (pch != NULL)
      {
      int x=999;
      Serial.print("string found ");
      Serial.println(pch);          // print it
      pch = strtok (NULL, "}]\[|{");     // get next token
     }  
}

void loop() {}

gives

Splitting string RL3][Test 1}|{3}|{S][Test 2}|{41}|{L][Test 3}|{1234}|{L into tokens:
string found RL3
string found Test 1
string found 3
string found S
string found Test 2
string found 41
string found L
string found Test 3
string found 1234
string found L

possibly use a structure or a class to store each item Test 1, 3, S

Below is an example of what the server sends me.

Whoever wrote the output like that should be fired.

What I need is to be able to save the data to however many variables I need.

You mean arrays, right? Storing each piece of data in a discrete variable makes no sense.

In order to store all the data in any list on the Arduino, there must be room for the largest possible list. So, rather than dynamically allocation space for the arrays, just determine what a reasonable length is for the arrays, and statically reserve that much space.