Thank you for your help! But I got the following message on the code when trying to compile your example:
error line: printf (" %4s %4s %4d\r", comrx, s, strcmp (comrx, s));
cannot convert 'String' to 'const char*' for argument '1' to 'int strcmp(const char*, const char*)'
if(Serial.available() > 0)
{
comrx = Serial.readStringUntil('\r');
Serial.println(comrx);
for (int i = 0; i <= 15; i++)
{
char s [10];
sprintf (s, "TO%d\r", i);
printf (" %4s %4s %4d\r", comrx, s, strcmp (comrx, s));
}
int n;
sscanf (comrx, "TO%d", & n);
Serial.print (n,HEX);
return 0;
}