You can use a specific radix
to parse the number into a long, increment it, and then convert it back to String.
If you're using all letters, then you can use 36
as the radix:
long number = Long.parseLong("ABB20180001", 36);
String incremented = Long.toString(number + 1, 36).toUpperCase();//"ABB20180002"
It's possible that your number is just a hexadecimal number. In that case, you can use 16
as the radix instead of 36
as shown above.
Note that if ABB
is just a prefix, then the above won't work (incrementing by 20 will return ABB2018000L
).
If "ABB"
is just a static prefix, then you can use
//if the prefix changes, a regex will be needed
String incremented = "ABB" + (Long.parseLong(string.replace("ABB", "")) + 1)
And finally, if "ABB"
can change, you can use a regex like this (the example below assumes that prefix is of length 3, change accordingly):
String s = "ABB20180001";
String[] parts = s.split("(?<=[A-Z]{3})"); //split after a sequence of 3 letters
String res = parts[0] + (Long.parseLong(parts[1]) + 1);