I have String str, from which I want to extract the sub-string excluding a possible prefix "abc".
The first solution that comes to mind is:
if (str.startsWith("abc"))
return str.substring("abc".length());
return str;
My questions are:
Is there a "cleaner" way to do it using
splitand a regular expression for an"abc"prefix?If yes, is it less efficient than the method above (because it searches "throughout" the string)?
If yes, is there any better way of doing it (where "better way" = clean and efficient solution)?
Please note that the "abc" prefix may appear elsewhere in the string, and should not be removed.
Thanks