These two functions have basically the same code. How can I factor it out?
public static String[] removeSuffix(String gA, String gB) {
String[] results = new String[2];
results[0] = gA;
results[1] = gB;
if (gA.equals("") || gB.equals("")) {
return results;
}
if (gA.charAt(gA.length() - 1) == gB.charAt(gB.length() - 1)) {
return removeSuffix(gA.substring(0, gA.length() - 1), gB.substring(0, gB.length() - 1));
}
else {
return results;
}
}
public static String[] removePrefix(String gA, String gB) {
String[] results = new String[2];
results[0] = gA;
results[1] = gB;
if (gA.equals("") || gB.equals("")) {
return results;
}
if (gA.charAt(0) == gB.charAt(0)) {
return removePrefix(gA.substring(1), gB.substring(1));
}
else { //if the first two chars are not equal
return results;
}
}