void setup() {
Serial.begin(9600);
}
void loop() {
String val;
while (Serial.available()==0);
val=Serial.readString();
val.trim(); // remove any \r \n whitespace at the end of the String (any leading and trailing whitespace removed)
Serial.println("The String entered is:");
Serial.println(val);
int position1 = val.indexOf(";");
Serial.println("First ; is at position:");
Serial.println(position1);
int position2 = val.indexOf(";" , position1 + 1); //looks for the next ";" after position1 +1
Serial.println("Second ; is at position:");
Serial.println(position2);
String FirstWord = val.substring(0, position1);
Serial.println("The first word is:");
Serial.println(FirstWord);
String SecondWord = val.substring(position1 + 1, position2);
Serial.println("The second word is:");
Serial.println(SecondWord);
String ThirdWord = val.substring(position2 + 1, val.length());
Serial.println("The third word is:");
Serial.println(ThirdWord);
}