I want to get an extract from a String. The extract should contain the 2 words in front of the keyword and the 2 words behind the keyword. If the 2 words doesn't exist, the sentence should just end.
Example:
The word im looking for is "example".
Existing Strings:
String text1 = "This is an example.";
String text2 = "This is another example, but this time the sentence is longer";
Result:
text1
should look like this:
is an example.
text2
should look like this:
is another example, but this
How can I do this?