below is my code that checks the incoming model and modifies the source accordingly, checking if its ALLCAPS or Firstcap. The problem I am having is when the model contains a symbol e.g. matchCase("I'm","apple"). This would return apple, when it's supposed to return Apple. On the other hand, If I use "Im", it modifies it correctly to "Apple". Is there a way i can modify it that would work. I tried to run a few methods but I keep getting stuck
public static String matchCase(String model, String source){
boolean o = true;
if(model.toUpperCase().equals(model)){
source = source.toUpperCase();
}
if(Character.isUpperCase(model.charAt(0))){
for(int i=1;i<model.length();i++){
if(Character.isLowerCase(model.charAt(i)) == false){
o = false;
}
}
// if(o == model.length()-1){
if(o == true){
String can = "";
for(int j=0;j<source.length();j++){
if(j==0){
can += Character.toUpperCase(source.charAt(j)); }
else{
can += source.charAt(j);
}
}
source = can;
// Character.toUpperCase(source.charAt(0));
}
}
return source;
}
}
sourcebe converted to ifmodeliscHecKand source ishELLO?