getting a substring from an unknown string in java

getting a substring from an unknown string in java

Hi everyone I'm wondering what is the best way to get a substring from a
string which is undefined until a user enters the string. For example if
the user enters 'abcdefg", how can I then get a substring "cde" I've
looked at the indexOf method but this seems to be used when the string is
already known