How to remove special characters from an string?

Total Post:128

Points:898

Java 
 1483  View(s)
Ratings:
Rate this:

I want to remove special character like:

- + ^ . : ,

from a string using java.

  1. 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

Please check, If you want to make this post sponsored

You are not a Sponsored Member. Click Here to Subscribe the Membership.