Essentially I need write a string method that receives two string arguments and replaces every character that exists in the second String with "" in the first. For example the first String toBeFixed = "I have a wonderful AMD CPU. I also like cheese." and the second String toReplaceWith ="oils". The string returned would be "I have a wnderfu AMD CPU. I a ke cheee."
Here is what I've got:
public class removeChars
{
public static String removeChars(String str, String remove)
{
String fixed = str.replaceAll(remove,"");
return(fixed);
}
}
I'm not sure if this is a misunderstanding of how the replaceAll method is used as I've seen things like
str = str.replaceAll("[aeiou]", "");
Ideally I'd figure out a way to toss my second string(remove) in there and then be done with it, but I'm not sure this is possible. I get a feeling this is a slightly more complicated problem... I'm not familiar with Array Lists and it seems the immutability of Strings might cause some issues for me.
This method should be able to deal with strings of any value entered. Any help or direction would be very much appreciated!