Question about Strings!

Hi!

In BASIC (BASCOM) programming when need to combine something like a variable with a constant text web do like following.

'Basic Code

Print "Sum is : "; S ; Chr(13)

'OR

Print "Code is : "; "{034}"; A ; "{034}"

How to perform it in C for ARDUINO?

Serial.print("Sum is :");
Serial.println(s);

You have several choices. This form:

void setup() {
/*  
  char part1[] = "Hello ";
  char part2[] = "World";
  char temp[12];
*/
  String part1 = "Hello ";
  String part2 = "World";

  Serial.begin(9600);
  Serial.print(part1 + part2);
/*

  Serial.print(part1);
  Serial.println(part2);
  // Or you can do this:
  strcpy(temp, part1);
  strcat(temp, part2);
  Serial.println(temp);
*/

}

void loop() {
  // put your main code here, to run repeatedly:

}

which uses the String class (note capital 'S'). It compiles to 3618 bytes. If you comment out the String statements and uncomment the others, the program compiles to 2244 bytes. Even though it "looks longer", C strings (note lower case 's') using char arrays are usually the preferred form since they use less code space and do not run the risk of fragmenting memory like Strings do.

Thanks a lot. My problem solved with your help. :slight_smile: