I'm trying to build one final method that will take a string such as
I will be the *greatest* hero ever!
and will look for the start and end asterisks, between them, whatever is there will be taken and made upper case, and then reinserting back in to look
I will be the GREATEST hero ever!
So far my code only takes whatever is between the asterisks and spits out only as a result:
"GREATEST"
I've been trying to correct this, and I've been told to use a function called "replace".
I found the reference here: a link
while(n4.hasNext()) {
sLine = n4.next();
F1 = sLine.indexOf("*");
L1 = sLine.indexOf("*", F1+1);
count = F1;
if (count < L1){
upperC = sLine.toUpperCase();
sLine = upperC.replace("*",upperC);
count++;
}
}
return sLine;
}
So far, this only outputs "all!"
after I try passing "To you the *victor* of all!"
Could someone please tell me what I'm missing or at least tell me where I can look to correct this?
UPDATE:
Here's the code so far, but now it's printing a sentence, but I'm still on the fence on how to replace the word between asterisks with a upper cased word that has no additional asterisks.
It prints: "To you the * * *VICTOR* * * of all!"
while(n4.hasNext()) {
sLine = n4.next();
s += sLine + " ";
F1 = sLine.indexOf("*");
L1 = sLine.indexOf("*", F1+1);
count = F1;
if (count < L1){
upperC = sLine.toUpperCase();
s = s.replaceAll("victor",upperC);
count++;
}
}
return s;
}