How to remove special characters from an string?

Total Post:128

Points:898
Java 
 1350  View(s)
Ratings:
Rate this:

I want to remove special character like:

- + ^ . : ,

from a string using java.

  1. Post:88

    Points:616
    Re: How to remove special characters from an string?

    Post is removed by the Admin.

  1. Post:88

    Points:616
    Re: How to remove special characters from an string?

    Try replaceAll() method of the String class.

    BTW here is the method, return type and parameters.

    public String replaceAll(String regex, String replacement)

    Example:

    String str = "Hello +-^ my + - friends ^ ^^-- ^^^ +!";
    str = str.replaceAll("[-+^]*", "");

    It should remove all the {'^', '+', '-'} chars that you wanted to remove!

      Modified On Mar-31-2018 04:33:48 AM

Answer