Such usage as this is found in many older sketches:
if (sim800.find("+CMGS"))
Most of the code compiles and runs, but sometimes, the compiler flags it as:
"class String' has no member named 'find'. Even after it has been compiled countless times. So I'm updating to index.
int index = text.indexOf(word);
// Check if the word was found
if (index >= 0) { // or (index != -1) { //if (text.find("+CMGS")) {
Serial.println("Word found");
Was 'find' once a member of String?
So then what about 'startsWith' as found in many code samples like this:
bool WaitForResponse()
{
unsigned long startTime = millis();
while (millis() - startTime < 5000)
{
String reply = ATCommandStream.readStringUntil('\n');
if (reply.length() > 0)
{
Serial.print("Received: \"");
Serial.print(reply);
Serial.println("\"");
if (reply.startsWith("OK"))
return true;
if (reply.startsWith("ERROR"))
return false;
}
}
Serial.println("Did not receive OK.");
return false;
}
This also produces:
error: 'class SoftwareSerial' has no member named 'startsWith'
the Stream class and classes inheriting from Stream like SoftwareSerial
will respond to a call to find(). It means receive data on the Stream until you find the expected target (or it times out)). It's documented here
The String class does not implement find(). If you want to check if a substring appears in a String, then you use indexOf(). The String class does not inherit from Stream.