HOW TO REMOVE SPECIAL CHARACTERS FROM AN STRING?

Ashish Pandey

Total Post:128

Points:898
Posted by  Ashish Pandey
Java 
 1264  View(s)
Ratings:
Rate this:

I want to remove special character like:

- + ^ . : ,

from a string using java.

  1. jacob rasel

    Post:88

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

    Post is removed by the Admin.

  1. jacob rasel

    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

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!