I am trying to get a substring out of a string. I have written logic to provide a start index and an end index but getting below exception. The code is:
final int startIndex = header.indexOf(startValue + ":")
+ (startValue + ":").length();
final int endIndex = header.indexOf(endValue + ":");
return header.substring(startIndex, endIndex).trim();
The exception:
'String index out of range: -4' java.lang.StringIndexOutOfBoundsException: String index out of range: -4 at java.lang.String.substring(String.java:1967)
Any help would be appreciated.