Open
Description
After uploading my sketch (using Arduino 1.6.8 and Arduino Uno),
void loop()
{
String str1 = "ACDEFG";
String str2 = "HIP";
String str3 = str1 + '\0' + str2;
Serial.println(str1);
Serial.println(str1.length());
Serial.println(str2);
Serial.println(str2.length());
Serial.println(str3);
Serial.println(str3.length());
Serial.println();
delay(10000);
}
I’m expecting to get as a result something like this:
ACDEFG
6
HIP
3
ACDEFG0HIP
10
But the result is:
ACDEFG
6
HIP
3
ACDEFG `ah
10
I.e. if I understand the problem correctly the String object keeps the right length of str3, but while copying the ‘\0’ it decides the string is over, but it’s not. So in str3 I get right symbols before ‘\0’ and some garbage after.