[solved, under 10 mins ;) ]How to put new contents into a string

With numbers I can do this, and it prints 5 followed by 10:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  int x = 5;
  Serial.println(x);
  x = 10;
  Serial.println(x);
}

void loop() {}

I hoped the same would be true with a string, so I tried this:

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  char stringx[]="foo";
  Serial.println(stringx);
  stringx[]="bar";
  Serial.println(stringx);
}

void loop() {}

It fails to compile, highlighting this line:

stringx[]="bar";

with the message:

expected primary-expression before ']' token

Evidently it's not as simple as replacing an int with a new value.

I can do this of course, but I'm really hoping there's a simpler way (not including using a for to do what I did here character by character):

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  char stringx[]="foo";
  Serial.println(stringx);
  stringx[0]='b';
  stringx[1]='a';
  stringx[2]='r';
  Serial.println(stringx);
}

void loop() {}

To recap: is there a way to replace a string in a way analogous to the way I can overwrite a number?

You have to use the strcpy (or strncpy) function to do it. For example :

  char stringx[]="foo";
  Serial.println(stringx);
 //  stringx[]="bar";
  strcpy(stringx,"bar");

Use strcpy or strncpy; you need to make sure that the destination is large enough to hold the largest text (including nul character).

man strcpy

stuart0:
You have to use the strcpy (or strncpy) function to do it.

Ok well that was easy, thanks. I knew there'd be a way.

Take a pound out the till, that man.

see also strcat()