Is there an easy way to trim a String based on his Offset and Count values, that is, a function that returns OO for a String FOOBAR with an offset of 1 and a count of 2?
Obvious, one could write a simple function for this task, but I wonder if their is not a predefined Java functionality for this?
//edit: To clearify: I do mean the offset and count values defined within the given String, not external Integer values.
EDIT: Okay, now you’ve made your question clearer, it sounds like this is the scenario you’re talking about, and the solution using the
String(String)constructor:Yup,
substring:substringtakes two parameters – the “begin index” (inclusive) and the “end index” (exclusive) – hence the addition in the above code.