I have a string/column something like this
String a = \"000003023_AggregateStopLossLimit_W x3A 973911_2012-12-22.PDF\";
I want to create a subs
replaceAll
takes a regex as an argument, if the substring contains regex markers (such as [
, +
for example) you will get an unexpected behaviour.
You can use replace
instead which does the same thing but takes a string as a parameter.
Apart from that, if you know that you will have a space and a _
as delimiters, AND the substring in between does not occur elsewhere, then your approach looks fine. You could possibly make it slightly more readable with intermediate variables:
int start = a.indexOf(" ");
int end = a.indexOf("_", start);
String b = a.substring(0, start) + a.substring(end, a.length());