I need to extract the substring "is a random te" but I only know the word random and the margins 5(characters) for left and 3 for right.
This is a random text
How can I do that?
I need to extract the substring "is a random te" but I only know the word random and the margins 5(characters) for left and 3 for right.
This is a random text
How can I do that?
You can use substring
like this
class Main {
public static void main(String args[]) {
String string = "This is a random text";
String match = "is a random te";
int i1 = string.indexOf(match);
int i2 = i1 + match.length();
System.out.println(string.substring(i1, i2));
}
}
Output
is a random te