substring returning empty

I have a humongous code where I do lots of thing, including gets from webservice. For that I have a method to get me the value given by the get: I created a pattern to identify here in the return is my variables, like #{ as for the start and closing with } and I have a method to return me that value:

String getResponseFromPHP(String response)
{
  int beginPosition = response.indexOf("#{") + 2;
  int endPosition = response.indexOf("}");

  return response.substring(beginPosition, endPosition);;
}

'response' in this case is the return from get, like:

HTTP/1.1 200 OK
Date: Fri, 28 Sep 2018 02:38:25 GMT
Server: Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.9
X-Powered-By: PHP/7.2.9
Content-Length: 115
Connection: close
Content-Type: text/html; charset=UTF-8

#{variable}

My problem is that this code worked perfectly until some time ago that the substring part simply stopped returning me any value, I already tested with other string, shorter and it worked changing the variables of start and end partially works, when they are big numbers like 219 and 329 (the case of the actual response string) it doesn't work, but if the numbers are like 150 and 200, it works.

Remembering that my code is big, with lots of functions. There can be any problem with disk space or anything ike that?

avoid the String class and use regular nul terminated C-strings. When you use the String class, your memory will get fragmented and eventually your code will fail as I'm guessing you have seen.

BTW, there isn't any "disk space" on an Arduino :slight_smile:

blh64:
avoid the String class and use regular nul terminated C-strings. When you use the String class, your memory will get fragmented and eventually your code will fail as I'm guessing you have seen.

BTW, there isn't any "disk space" on an Arduino :slight_smile:

Ok, and how should I use the C-strings?

B4rbosa:
Ok, and how should I use the C-strings?

by reading what the functions in those libraries do: stdlib.h and string.h

A C-String is (most often) declared as an array of char. However, an array of char is NOT by itself a C-String. A valid one requires the presence of a terminating "null character", that is a character with ASCII value 0, usually represented by the character literal '\0'.