I have a static method that searches (and returns) into String msg the value between a TAG
this is the code function:
static String genericCutterMessage(String TAG, String msg){ Serial.print("a-----"); Serial.println(msg); Serial.print("b-----"); Serial.println(TAG); if(msg.indexOf(TAG) >= 0){ Serial.print("msg "); Serial.println(msg); int startTx = msg.indexOf(TAG)+3; int endTx = msg.indexOf(TAG,startTx)-2; Serial.print("startTx "); Serial.println(startTx); Serial.print("endTx "); Serial.println(endTx); String newMsg = msg.substring(startTx,endTx); Serial.print("d-----"); Serial.println(newMsg); Serial.println("END"); Serial.println(newMsg.length()); return newMsg; } else { Serial.println("d-----TAG NOT FOUND"); return ""; } } and this is output
a-----[HS][TS]5132[/TS][TO]5000[/TO][/HS] b-----HS msg [HS][TS]5132[/TS][TO]5000[/TO][/HS] startTx 4 endTx 30 d----- END 0 fake -_-'....go on! <-- print out of genericCutterMessage in that case I want return the string between HS tag, so my expected output is
[TS]5132[/TS][TO]5000[/TO] but I don't know why I receive a void string.
to understand how substring works I just followed tutorial on official Arduino site
http://www.arduino.cc/en/Tutorial/StringSubstring
I'm not an expert in C++ and Arduino but this looks like a flushing or buffering problem, isn't it?
Any idea?
Serial.println(newMsg.length());?serial.println("END");, and double check that the wordENDappears at the end of the printout.Serial.flush()afterSerial.println(newMsg);change anything?