String.startsWith returning invalid results

cmd is a string. When I use cmd.startsWith(), it returns false always, even when I check using the serial port to see that it is right.

  Serial.print("CMD=");
  Serial.println(cmd);
  Serial.print("cmd.startsWith(\"FIRE:\")=");
  Serial.println(cmd.startsWith("FIRE:"));
  if (cmd.startsWith("FIRE:")) <----------------------------- returns zero always
  {
    cmd.replace("FIRE:","");
    Serial.print("entered Fire:");
    Serial.println(cmd);

Here is the serial output:

CMD=FIRE:A1999B1C1D9EF9GH9IJ3KL9M1N1O1P1Q1R1S1T
cmd.startsWith("FIRE:")=0

What am I missing? This worked until recently. I have been working on an unrelated section of the code.

Please help, very confused…

Thanks,
Josh Hawley

This worked until recently.

That code does look like it should work.

As you are using strings, are you conscious of how much ram you have left? Low ram can cause anything magical to happen.
Verify it on a stand alone sketch, just with that basic functionality you have posted above.

pYro_65:
As you are using strings, are you conscious of how much ram you have left? Low ram can cause anything magical to happen.

Thank you! This turned out to be spot on. I spent a couple hours or so after reading your post removing every reference to the string library. Now it is working just fine, and its 4k smaller too.

Josh Hawley

Thank you! This turned out to be spot on. I spent a couple hours or so after reading your post removing every reference to the string library.

What a waste of effort. Now, removing every reference to the String library would have been a good use of your time.

Lol true enough. I See what you did there ;p