Update variables in array?!?

Hi,

I am writing a sketch to display MQTT topics/messages on a OLED display. Displayed is the string "msgtopicx".

display->drawString(0 + x, 10 + y, String(msgtopic1));
display->drawString(0 + x, 20 + y, String(msgtopic2));
display->drawString(0 + x, 30 + y, String(msgtopic3));
display->drawString(0 + x, 40 + y, String(msgtopic4));

I'm defining the topics that should be subscribed and info "around" these topics:

//Topic 1
char* topic1 = "/Wohnung/Schlaf/temp";
char* pre_topic1 = "Temp:     ";
char* post_topic1 = "°C     ";
char* post2_topic1 = "";
String msgtopic1 = "(T1)Temp: waiting for data";

//Topic 2
char* topic2 = "/Wohnung/Schlaf/humidity";
char* pre_topic2 = "Humidity: ";
char* post_topic2 = "%";
char* post2_topic2 = "  ";
String msgtopic2 = "(T2)Humidity: waiting for data";

//... until topic8

I'm defining the topics to subscribe (later called in callback function):

//Subscribe topics
char* subscribe_mqtt_topic[] ={ topic1,   //#0
                                      topic2,   //#1
                                      topic3,   //#2
                                      topic4,   //#3
                                      topic5,   //#4
                                      topic6,   //#5
                                      topic7,   //#6
                                      topic8    //#7
                                           };
//-------------------------------------------------------------------------------
String msg_topic[] ={ msgtopic1,   //#0
                           msgtopic2,   //#1
                           msgtopic3,   //#2
                           msgtopic4,   //#3
                           msgtopic5,   //#4
                           msgtopic6,   //#5
                           msgtopic7,   //#6
                           msgtopic8    //#7
                                           };

In the MQTT callback function I compare the incoming topic with the topics and assemble the display string accordingly:

void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.println();
  Serial.print("New message: [");
  Serial.print(topic);
  Serial.print("] with data: ");
int n = 100;

if (strcmp(topic,topic1)==0)
  {
    msgtopic1 = "";
    msgtopic1 += pre_topic1;
    for(int i=0;i<4;i++) //limit temp to 3 digit
    //for(int i=0;i<length;i++)
    {
      Serial.print((char)payload[i]);  
      msgtopic1 += (char)payload[i];
    } 
    msgtopic1 += post_topic1;
    msgtopic1 += post2_topic1;
    n = 0;
    Serial.println();
    Serial.print("msg_topic n = ");
    Serial.print(n);
    Serial.print(" -- msgtopic1: [");
    Serial.print(msgtopic1);
    Serial.print("] -- msg_topic[n]: [");
    Serial.print(msg_topic[n]);
    Serial.print("]");
  }
  
  if (strcmp(topic,topic2)==0) 
  {
    msgtopic2 = "";
    msgtopic2 += pre_topic2;
    for(int i=0;i<4;i++) //limit humidity to 3 digit
    //for(int i=0;i<length;i++)
    {  
      Serial.print((char)payload[i]);
      msgtopic2 += (char)payload[i];
    }
    msgtopic2 += post_topic2;
    msgtopic2 += post2_topic2;
    n = 1;
    Serial.println();
    Serial.print("msg_topic n = ");
    Serial.print(n);
    Serial.print(" -- msgtopic2: [");
    Serial.print(msgtopic2);
    Serial.print("] -- msg_topic[n]: [");
    Serial.print(msg_topic[n]);
    Serial.print("]");
  }

//...up to topic8

This is complicated (one could probably do this without string assembly and just assemble on display but that sort of just moves the problem elsewhere) but works.

Now the question:

I try to get rid of all those assembly if and just want to write "if topic = topic1 then n = 0" and with n=0,1,2,... a msg_topic[n] is assembled and I can display msgtopicX.

BUT, although msg_topic[n] seems to get the inital value defined in eg "String msgtopic1 = "(T1)Temp: waiting for data";", msg_topic[n] doesn't seem to be able to update the msgtopicX string. - so, what I want to do is to "write into msgtopix by writing into msg_topic[n]". If msgtopicx is updated (got new data), msg_topic[n] seems to keep the old, original value...

when running the code I get:

New message: [/Wohnung/Schlaf/temp] with data: 24.0
msg_topic n = 0 -- msgtopic1: [Temp:     24.0°C     ] -- msg_topic[n]: [(T1)Temp: waiting for data]
New message: [/Wohnung/Schlaf/humidity] with data: 53.9
msg_topic n = 1 -- msgtopic2: [Humidity: 53.9%  ] -- msg_topic[n]: [(T2)Humidity: waiting for data]

Does anybody have a good idea how to solve the problem overall or at least point me in the right direction to understand on how to update the varibales in the array (is it actually an array?)?

Many thanks!!

PS: If anybody actually has a good idea to make all this easier (as it is always 1,2,3...), any comment is welcome!

sorry, I actually forgot to added the definition of

String msg_topic[] ={ msgtopic1, //#0
msgtopic2, //#1
msgtopic3, //#2
msgtopic4, //#3
msgtopic5, //#4
msgtopic6, //#5
msgtopic7, //#6
msgtopic8 //#7
};

edited and added in first post.

If anybody actually has a good idea to make all this easier (as it is always 1,2,3...), any comment is welcome!

First, you rewrite the sketch to completely remove ALL uses of the String class. Then, manipulating the arrays becomes far easier.