Get value between letters in string

Hello,

I got this string:
GET /ajax_inputsP1i2d3s4n6o7h5x&nocache=596588.5785801635 HTTP/1.1

In this string P got the value 1;
I = 2, D = 3, S = 4, n = 6, h = 5.

I want to extract these values so I can work with them and put them in a INT.

My code:

char str[] = "GET /ajax_inputsP1i2d3s4n6o7h5x&nocache=596588.5785801635 HTTP/1.1";
char *P;             // pointer to P
char *P1;
char *I;               // pointer to I

void setup(){
Serial.begin(9600);
}

void loop(){
P = strstr(str, "P");
P += 1;
Serial.print(P);
Serial.println();
I = strstr(P, "i");
I[0] =0;
P1 = strlen(P);
Serial.print(P1);
Serial.println();

delay(1000);

 
   }

Gives this error:
exit status 1
invalid conversion from 'size_t {aka unsigned int}' to 'char*' [-fpermissive]

P1 is the value between P and I.
How do I get this values from the string into a INT to work with it? :frowning:
thanks in advance

I'm no expert on this stuff and I have just been doing a bit of Googling. I think the function strcspn() would give you the index into the char array and then you could work your way along from that. Find the location of 'P' and get the next character and the next and the next

...R

Thanks for replying Robin!
I also looked at that when googling to a solution.

With strcspn() you look to a for a match.

  char str[] = "fcba73";
  char keys[] = "1234567890";
  int i;
  i = strcspn (str,keys);
  printf ("The first number in str is at position %d.\n",i+1);
  return 0;

But in my case, the value of P can everything. :frowning:

The below extracts the part that you marked in bold.

char incoming[] = "GET /ajax_inputsP1i2d3s4n6o7h5x&nocache=596588.5785801635 HTTP/1.1";


void setup()
{

  Serial.begin(9600);
  char *ptrStart = incoming + strlen("GET /ajax_inputs");
  char *ptrEnd = strchr(ptrStart, '&');
  *ptrEnd = '\0';
  Serial.println(ptrStart);


}

void loop()
{

}

You need to harden the code. The strlen() should be shorter than the length of incoming.
You should also check if ptrEnd is not NULL.

If you don't do these things, you might end up with random problems that can be hard to find.

Next iterating through the ptrStart to find every second character should be easy.

How about Serial.find or Serial.finduntil?