There is now a SafeString library available from the Arduino Library manager which includes a number of tokenizer methods and a simple effective example of parsing user input for keywords without blocking the rest of the sketch from running
SafeStrings do not cause heap fragementation and never cause the sketch to reboot and have detail debugging available.
void loop() {
input.read(Serial)
// read from Serial, returns true if at least one character was added to SafeString input
if (input.nextToken(token, delimiters)) { // process at most one token per loop does not return tokens longer than input.capacity()
if (token == startCmdStr) {
running = true; Serial.print(F("start at ")); Serial.println(loopCounter);
} else if (token == stopCmdStr) {
running = false; Serial.print(F("stop at ")); Serial.println(loopCounter);
} else if (token == resetCmdStr) {
loopCounter = 0; Serial.print(F("reset Counter:")); Serial.println(loopCounter);
}// else // not a valid cmd ignore
}
// rest of code here is executed while the user typing in commands
if (running) {
loopCounter++;
if ((loopCounter % 100000) == 0) {
Serial.print(F("Counter:")); Serial.println(loopCounter);
}
}
}