I have implemented a very simple method:
private String getProfileName(String path) {
String testPath = null;
for (int i = 0; i < path.length(); i++) {
testPath = path.substring(0, i);
if ( testPath.endsWith("1") || testPath.endsWith("2") || testPath.endsWith("3") || testPath.endsWith("4") || testPath.endsWith("5") || testPath.endsWith("6") || testPath.endsWith("7") || testPath.endsWith("8") || testPath.endsWith("9") ) {
break;
}
}
return testPath.substring(0, (testPath.length() - 1));
}
I don't like the whole method because I think it's more complicated than necessary, especially the if condition.
So I thought of a way to refactor this method. First I thought of using Regex to replace the if condition, but isn't regex a little bit too much for this simple case?
Any other ideas how to reafctor this?