apparently I've run into a bug in regards to the String library.
The odd part is, I've used the startsWith method before, and it worked a treat.
But whenever I try to use it now, it always returns true.
I tried it with the old v0.4 library, the v0.8 library (both the one I had, and a fresh download), but it keeps returning true.
Won't include the library in this post, as I've been using an unmodified version of the one found on this site.
Sketch used for testing purposes:
#include <WString.h>
void setup()
{
Serial.begin(9600);
String test = "foo";
if(test.startsWith("f")) { Serial.println("starts with f"); }
if(test.startsWith("bar")) { Serial.println("starts with bar"); }
if(test.startsWith("far too large a string")) { Serial.println("I'm stumped"); }
}
void loop()
{
}
I use ubuntu 9.10, and I have a feeling it has something to do with an update or so (the usual culprit when something stops working for no apparent reason), but it remains quite annoying.
The arduino I'm using is a DFRduino duemilanove with Atmega328 chip.
Anybody have an idea for a work-around, fix or cause to this bug?
And just as suddenly as this bug appeared, it vanishes?
I copy-pasted the old v0.4 library back in my 018 folder, and suddenly it works again (was going to give it another round of debugging).
:o
This makes me wonder, this would imply that the error isn't in the code..
Could this bug be related to the IDE? like the 'my program disappeared!' bug mentioned here?
The constructor in my version appears to be fine.
The clear() method sets the entire array to null characters, it doesn't reset the length.
So it resets the array, then writes the argument to the array.
Appears to be solid code :-/
Still no idea what caused this bug, it disappeared as randomly as it appeared.
Thanks for the discoveries, and sorry for my delay in replying to this. We've never included String in the core libraries partially because it's always been a little buggy and not ready for prime time. One of my colleagues and I are doing some work to improve that in the coming weeks, though, and I hope we'll have a new version up soon.