Hai all, Noob here help needed
i am trying to extract the data from my server response individually and assign them to different variables.
Here’s my function to get the data
//function
String getValue(String data,char separator,int index)
{
int found = 0;
int strIndex[] = {0,0};
int maxIndex = data.length()-1;
for(int i=0;i<=maxIndex && found<=index;i++){
if(data.charAt(i)==separator || i==maxIndex){
found++;
strIndex[0] = strIndex[1]+1;
strIndex[1] = (i == maxIndex) ? i+1: i;
}
}
String check = found>index ? data.substring(strIndex[0],strIndex[1]) : "";
return check;
}
and my invokation part and assignment part shared below
Serial.println(status);
Serial.print("value 1 --->");
String index0 = getValue(status, ',',0);
Serial.println(index0);
Serial.print("value 2 --->");
String index1 = getValue(status, ',',1);
Serial.println(index1);
my server response is 0,1,
now i want my index0 variable to have 1st value which is at the 0th index ie,0 and index1 to hold the value at the 1st index ie,1
but my function shared above is able to get the value in 1st index but not 0th index
here’s the result that i am getting
0,0,
value 1 --->
value 2 --->0,
can any one help me with this issue?