Search code examples
javaandroidstringreplaceall

java replacing multiple characters in a string including "\u00A2"


I have a string with "Dollars" and "Cents" symbol in it. I want to remove them. I tried

string.replaceAll("[\"\\u00A2\" $]", "")

but its not working. What is the correct way to do it.


Solution

  • string = string.replaceAll("¢|\\$", "");
    

    or

    string = string.replaceAll("\\u00A2|\\$", "");
    

    $ is a special character in regular expressions, so you have to escape it, unless it's in a character class.