Amend text in a string array

Hi, I wonder if anybody could help me with this:

I have a string array as below

char* myStrings={“This is string 1”, “This is string 2”, “This is string 3”,
“This is string 4”, “This is string 5”,“This is string 6”};

and for a reason that I don’t want to dick in, I would like to amend the numbers of the individual strings. Therefore i first would like to define an int such as

int temp=7;

Then I would like to amend a chosen string to change the number at the end. I tried this:

myStrings[1] = “This is string”;
myStrings[1] += temp;

I hoped to get the following result:
This is string is string 7

What am I doing wrong. Many thanks for your help.

Full code:

char* myStrings={“This is string 1”, “This is string 2”, “This is string 3”,
“This is string 4”, “This is string 5”,“This is string 6”};
void setup(){
Serial.begin(9600);
}

void loop(){
int temp=7;
for (int i = 0; i < 6; i++){
Serial.println(myStrings*);*

  • delay(500);*
  • }*
  • myStrings[1] = “This is string is new”;*
  • myStrings[1] += temp;*
  • for (int i = 0; i < 6; i++){*
    _ Serial.println(myStrings*);_
    _
    delay(500);_
    _
    }_
    _
    }*_

"+= String(temp);" ?

(Sorry, I don't use Strings)

Please remember to use code tags when posting code

@AWOL: Hmm I am quite new to strings. This += solution i saw somewhere in the WWW, but I think this only works with strings not with string arrays...

Ps: If i use wrong experessions/words please let me know.

*(myStrings[i]+15) = '0' + theNewNumber;I think... and even if it works, I wouldn't do it.

that works thank

Bastop:
that works thank

You're welcome, but it's a terrible design. Something like a struct containing a string and an int, and a print method for it, would be vastly better.

yea i know. I had to do it like this to be able to integrate this into an existing quite complex code for an lcd display... i am learning like this. thanks again.

Bastop:
yea i know. I had to do it like this to be able to integrate this into an existing quite complex code for an lcd display... i am learning like this. thanks again.

Well, it stretched my brain so I learned something from it too.

Now, i am realising, I am not quite at the finish line yet.

Actually this needs to work also if i define “myString” as a String variable and NOT as a *char. I tried this below, the whole thing complies but the value at

(myStrings[3]+15) = ‘0’ + temp;

is not being amended. Any idea what I have to do differently?

Here is the code:

String myStrings={“This is string 1”, “This is string 2”, “This is string 3”,
“This is string 4”, “This is string 5”,“This is string 6”};

void setup(){
Serial.begin(9600);
}

void loop(){
int temp=2;
for (int i = 0; i < 6; i++){
Serial.println(myStrings*);*

  • delay(500);*

  • }*

  • (myStrings[3]+15) = ‘0’ + temp;*

  • for (int i = 0; i < 6; i++){*
    _ Serial.println(myStrings*);_
    _
    delay(500);_
    _
    }_
    _
    }*_

Oops sorry - I responded to the wrong thread !

Please remember to use code tags when posting code

If you must use the String class (not recommended on limited memory processors), then it provides a plethora of methods to manipulate the text. Check out the reference:
https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/