Hello everyone,
I am trying to extract certain data from a string. When i print the extracted data using the serial monitor it displays the right data. But, if i assign the extracted data to a variable and print that variable using the serial monitor i get all wrong data. Does anyone know where did it go wrong.
String qty,price,landed,delv;
String url = "2,40.500,18.000,1.500";
void setup() {
Serial.begin(9600);
}
void loop() {
//locate the ","
int firstcom = url.indexOf(",");
int secondcom = url.indexOf(",",firstcom+1);
int thirdcom = url.indexOf(",",secondcom+1);
//Assign extracted data to variables
qty = url.substring(0,firstcom);
price = url.substring((2,8));
landed = url.substring((9,15));
delv = url.substring(thirdcom+1);
//Print the index of the ","
Serial.println(firstcom);
Serial.println(secondcom);
Serial.println(thirdcom);
//print the extracted data...it prints right
Serial.println( url.substring(0,firstcom));
Serial.println( url.substring(firstcom+1,secondcom));
Serial.println( url.substring(secondcom+1,thirdcom));
Serial.println( url.substring(thirdcom+1));
//print the variables that contains extracted data...it prints wrong
Serial.println(qty);
Serial.println(price) ;
Serial.println(landed) ;
Serial.println(delv) ;
delay(3000);
}