Pages

Remove Special Characters in a String - Java

To remove special characters in a string, replaceAll is used.Example of replaceAll follows below











public class example
{
     public static void main(String[] args)
     {
          String price="$5.00";
          String newPrice=price.replaceAll("\\$","");
          System.out.println("New Price "+newPrice);
     }
}

Output:
New Price 5.00