How to extract data from server and assign it to the variable using nodeMCU ?

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?

your code is convoluted and difficult to follow without comments
have a look at the String tokeniser which is useful to extract fields from a String

in general String are not recommended on the Arduino and can cause problems

try the C character string tokeniser strtok()
https://www.tutorialspoint.com/c_standard_library/c_function_strtok.htm

e.g.

int main ()
{
  char str[] ="0,1,";
  char * pch;
  printf ("Splitting string \"%s\" into tokens:\n",str);
  pch = strtok (str,",");
  while (pch != NULL)
  {
    printf ("token found found %s\n",pch);
    pch = strtok (NULL, ",");
  }
  return 0;
}

when run gives

Splitting string "0,1," into tokens:
token found found 0
token found found 1