Reputation: 55
I need help deleting "fe" from sWord in the System.out part of the code. Just need a quick answer on how to do this, its clear that you cant simply subtract it but I don't know how else to do it, thanks for the help. BTW this is not the full code, simply an excerpt.
else if (sWord.substring(sWord.length()-2,sWord.length()).equalsIgnoreCase("fe"))
{
System.out.println("The Plural of" + sWord + "is" + **(sWord-("fe"))** + "ves");
}
Upvotes: 1
Views: 110
Reputation: 22392
How about :
sWord.replace("fe", "");
For more information about replace you can take a look here
Upvotes: 0
Reputation: 1323
You can use String replace() method:
String newSWord = sWord.replace("fe", "");
If you need some advanced String modification, you can have a look at Apache Commons Lang library - StringUtils replace() method.
Upvotes: 0
Reputation: 201447
If it's only at the end of the string (as in your example), you could do
sWord = sWord.substring(0, sWord.length()-2);
If you want to remove "fe" from anywhere in the sWord
you could use,
sWord = sWord.replace("fe", "");
Upvotes: 1