In trying to use the String class function substring, I get the following error:
undefined reference to `String::operator=(String&&)’
I suspect this is caused by a bug in the implementation of this in the String class, so I have simplified the problem into a few code lines so everyone can experience it / troubleshoot themselves, just attempt to verify this code to reproduce the error:
void setup() {
Serial.begin(9600);
String myString;
String mySubstring;
myString = "1. This is a test string";
mySubstring = myString.substring(4,18);
Serial.println(mySubstring);
}
void loop() { }
Thanks for the input, but while that does work in the code excerpt that I posted, the compiler does not like re-declaring variables, so that would not let me use it as an actual variable such as:
void setup() {
Serial.begin(9600);
String myString;
myString = "1. This is a test string";
myString2 = "2. This is also a test string";
String mySubstring = myString.substring(4,18);
Serial.println(mySubstring);
String mySubstring = myString2.substring(4,23);
Serial.println(mySubstring);
}
void loop() { }
This does actually work in the code where I am implementing this. In my case it creates a new value for the mySubstring variable in every iteration of a loop, unfortunately it does require that the variable is re-declared every iteration as well which at the very least is messy… but it does work.
I do appreciate the input, it allows me to continue until the implementation of the String class is fixed.
Thanks!
The code for that operator in the String class is commented out with an #ifdef for an experimental version of the C compiler. I don’t know why, but I suspect it does not work in the current compiler.
The best way I have found to deal with this is set the string to empty and then concatenate.
Concatenate always copies data from one String to another, while the original code is trying to change the pointer for mySubString to point to a new instance of String.