so I'm parsing html and I'm trying to create a substring starting at a certain location and stop 941 characters after that. The way the .substring method in Java works is you have to give it a start location and a end location but the end location needs to be a location on the original string after the start.
String html = "This is a test string for example";
html.substring(html.indexOf("test"), 6);
This is an example of how I would like the code to work, it would make a substring starting at test and stop after 7 characters returning "test string". However if I use this code I get a indexOutOfBounds exception because 6 is before test. Working code would be the following
String html = "This is a test string for example";
html.substring(html.indexOf("test"), 22);
Which would return "test string". But I don't know what the last number is going to be since the html is always changing. SO THE QUESTION IS what do I have to do so that I can start a specific location and end a x amount of characters after it? Any help would be much appreciated! Thanks!